mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
added restart in task detail
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
// 上传爬虫
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user