From 4e4807a6a4ad1fe5629779ee28d59cc8351d5fd8 Mon Sep 17 00:00:00 2001 From: marvzhang Date: Sat, 18 Jul 2020 11:43:34 +0800 Subject: [PATCH] added batch restart tasks --- .../components/Common/BatchCrawlDialog.vue | 5 +++ frontend/src/i18n/zh.js | 3 ++ frontend/src/store/modules/task.js | 5 +++ frontend/src/views/spider/SpiderList.vue | 11 +++---- frontend/src/views/task/TaskList.vue | 31 ++++++++++++++++++- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/Common/BatchCrawlDialog.vue b/frontend/src/components/Common/BatchCrawlDialog.vue index c7a0cd7f..42b6647f 100644 --- a/frontend/src/components/Common/BatchCrawlDialog.vue +++ b/frontend/src/components/Common/BatchCrawlDialog.vue @@ -212,6 +212,7 @@ scrapy_log_level: 'INFO' }) } + this.$st.sendEv('批量运行', '重置') }, getSpiderById(id) { return this.allSpiderList.filter(d => d._id === id)[0] || {} @@ -225,6 +226,7 @@ this.$set(row, 'scrapy_spider_name', this.scrapySpidersNamesDict[id][0]) } } + this.$st.sendEv('批量运行', '选择爬虫') }, getScrapySpiderNames(id) { if (!this.scrapySpidersNamesDict[id]) return [] @@ -241,6 +243,7 @@ })) this.reset() this.$emit('close') + this.$st.sendEv('批量运行', '确认批量运行') }, async fetchScrapySpiderNames(id) { if (!this.scrapySpidersNamesDict[id]) { @@ -269,9 +272,11 @@ param: '', scrapy_log_level: 'INFO' }) + this.$st.sendEv('批量运行', '添加') }, onRemove(rowIndex) { this.batchCrawlList.splice(rowIndex, 1) + this.$st.sendEv('批量运行', '删除') } } } diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js index 70e123b8..02069c48 100644 --- a/frontend/src/i18n/zh.js +++ b/frontend/src/i18n/zh.js @@ -668,6 +668,9 @@ export default { 'Are you sure to stop these tasks': '确认停止这些任务?', 'Are you sure to delete these tasks': '确认删除这些任务?', 'Stopped successfully': '成功停止', + 'Are you sure to restart these tasks': '确认重新运行这些任务?', + 'Restarted successfully': '成功重新运行', + 'Are you sure to stop this task?': '确认停止这个任务?', // 其他 'Star crawlab-team/crawlab on GitHub': '在 GitHub 上为 Crawlab 加星吧' diff --git a/frontend/src/store/modules/task.js b/frontend/src/store/modules/task.js index e4a4ecd8..59e972c6 100644 --- a/frontend/src/store/modules/task.js +++ b/frontend/src/store/modules/task.js @@ -259,6 +259,11 @@ const actions = { return await request.post(`/tasks-cancel`, { ids }) + }, + async restartTaskMultiple({ dispatch }, ids) { + return await request.post(`/tasks-restart`, { + ids + }) } } diff --git a/frontend/src/views/spider/SpiderList.vue b/frontend/src/views/spider/SpiderList.vue index 8d4a2f8c..58760fcc 100644 --- a/frontend/src/views/spider/SpiderList.vue +++ b/frontend/src/views/spider/SpiderList.vue @@ -1310,6 +1310,7 @@ this.$message.success(`Task "${row._id}" has been sent signal to stop`) this.getList() } + this.$st.sendEv('爬虫列表', '任务列表', '停止任务') }, onIsScrapy(value) { if (value) { @@ -1331,7 +1332,7 @@ spider_ids: this.selectedSpiders.map(d => d._id) }) if (!res.data.error) { - this.$message.success('Delete successfully') + this.$message.success('Deleted successfully') this.$refs['table'].clearSelection() await this.getList() } @@ -1359,13 +1360,9 @@ } finally { this.isStopLoading = false } - this.$st.sendEv('爬虫列表', '批量删除爬虫') + this.$st.sendEv('爬虫列表', '批量停止爬虫') }) }, - onCrawlSelectedSpiders() { - this.crawlConfirmDialogVisible = true - this.isMultiple = true - }, onBatchCrawl() { this.$store.commit('task/SET_BATCH_CRAWL_LIST', this.selectedSpiders.map(d => { return { @@ -1387,6 +1384,7 @@ } this.batchCrawlDialogVisible = true this.isMultiple = true + this.$st.sendEv('爬虫列表', '点击批量运行') }, onCrawlConfirmDialogClose() { this.crawlConfirmDialogVisible = false @@ -1415,6 +1413,7 @@ this.isMultiple = false await this.getList() }) + this.$st.sendEv('爬虫列表', '批量设置项目') } } } diff --git a/frontend/src/views/task/TaskList.vue b/frontend/src/views/task/TaskList.vue index 02121446..16076860 100644 --- a/frontend/src/views/task/TaskList.vue +++ b/frontend/src/views/task/TaskList.vue @@ -203,7 +203,7 @@ :width="col.width" /> - + @@ -424,6 +432,7 @@ message: resp.data.error }) }) + this.$st.sendEv('任务列表', '批量重启任务') }).catch(() => { }) }, @@ -449,6 +458,7 @@ message: resp.data.error }) }) + this.$st.sendEv('任务列表', '批量删除任务') }).catch(() => { }) }, @@ -474,6 +484,7 @@ message: resp.data.error }) }) + this.$st.sendEv('任务列表', '批量停止任务') }).catch(() => { }) }, @@ -511,6 +522,24 @@ this.$st.sendEv('任务列表', '重新开始任务') }) }, + onStop(row, ev) { + ev.stopPropagation() + this.$confirm(this.$t('Are you sure to stop this task?'), this.$t('Notification'), { + confirmButtonText: this.$t('Confirm'), + cancelButtonText: this.$t('Cancel'), + type: 'warning' + }).then(() => { + this.$store.dispatch('task/cancelTask', row._id) + .then(() => { + this.$message({ + type: 'success', + message: this.$t('Stopped successfully') + }) + this.$store.dispatch('task/getTaskList') + }) + this.$st.sendEv('任务列表', '停止任务') + }) + }, onView(row) { this.$router.push(`/tasks/${row._id}`) this.$st.sendEv('任务列表', '查看任务')