added restart in task detail

This commit is contained in:
marvzhang
2020-07-18 21:44:39 +08:00
parent 1fbed2679d
commit d63c89d447
2 changed files with 45 additions and 16 deletions

View File

@@ -55,20 +55,31 @@ func DownloadRepo(fullName string, userId bson.ObjectId) (err error) {
}
// 创建爬虫
spider := model.Spider{
Id: bson.NewObjectId(),
Name: spiderName,
DisplayName: spiderName,
Type: constants.Customized,
Src: spiderPath,
ProjectId: bson.ObjectIdHex(constants.ObjectIdNull),
FileId: bson.ObjectIdHex(constants.ObjectIdNull),
UserId: userId,
}
if err := spider.Add(); err != nil {
log.Error("add spider error: " + err.Error())
debug.PrintStack()
return err
spider := model.GetSpiderByName(spiderName)
if spider.Name == "" {
// 新增
spider := model.Spider{
Id: bson.NewObjectId(),
Name: spiderName,
DisplayName: spiderName,
Type: constants.Customized,
Src: spiderPath,
ProjectId: bson.ObjectIdHex(constants.ObjectIdNull),
FileId: bson.ObjectIdHex(constants.ObjectIdNull),
UserId: userId,
}
if err := spider.Add(); err != nil {
log.Error("add spider error: " + err.Error())
debug.PrintStack()
return err
}
} else {
// 更新
if err := spider.Save(); err != nil {
log.Error("save spider error: " + err.Error())
debug.PrintStack()
return err
}
}
// 上传爬虫

View File

@@ -71,6 +71,9 @@
</el-form>
</el-row>
<el-row class="button-container">
<el-button size="small" type="warning" icon="el-icon-refresh" @click="onRestart">
{{ $t('Restart') }}
</el-button>
<el-button v-if="isRunning" size="small" type="danger" icon="el-icon-video-pause" @click="onStop">
{{ $t('Stop') }}
</el-button>
@@ -100,13 +103,28 @@
}
},
methods: {
onRestart() {
},
onStop() {
this.$store.dispatch('task/cancelTask', this.$route.params.id)
.then(() => {
this.$message.success(`Task "${this.$route.params.id}" has been sent signal to stop`)
})
this.$st.sendEv('任务详情', '概览', '停止任务')
},
onRestart() {
this.$confirm(this.$t('Are you sure to restart this task?'), this.$t('Notification'), {
confirmButtonText: this.$t('Confirm'),
cancelButtonText: this.$t('Cancel'),
type: 'warning'
}).then(() => {
this.$store.dispatch('task/restartTask', this.taskForm._id)
.then(() => {
this.$message({
type: 'success',
message: this.$t('Restarted successfully')
})
})
this.$st.sendEv('任务详情', '概览', '重新开始任务')
})
},
getTime(str) {
if (!str || str.match('^0001')) return 'NA'