From 6bb90f56fa9c937049336ec918b858523e0b2e2f Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 15 Mar 2019 13:48:17 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=83=96=E3=82=92=E4=B8=80?= =?UTF-8?q?=E8=A6=A7=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/app/admin/views/queue.vue | 69 ++++++++++++++++++-- src/server/api/endpoints/admin/queue/jobs.ts | 40 ++++++++++++ 2 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 src/server/api/endpoints/admin/queue/jobs.ts diff --git a/src/client/app/admin/views/queue.vue b/src/client/app/admin/views/queue.vue index cec2ab4d7c..17bf3709cf 100644 --- a/src/client/app/admin/views/queue.vue +++ b/src/client/app/admin/views/queue.vue @@ -1,7 +1,7 @@ @@ -69,7 +98,7 @@ import i18n from '../../i18n'; import ApexCharts from 'apexcharts'; import * as tinycolor from 'tinycolor2'; import { faTasks, faInbox, faStopwatch, faPlayCircle as fasPlayCircle } from '@fortawesome/free-solid-svg-icons'; -import { faPaperPlane, faStopCircle, faPlayCircle as farPlayCircle } from '@fortawesome/free-regular-svg-icons'; +import { faPaperPlane, faStopCircle, faPlayCircle as farPlayCircle, faChartBar } from '@fortawesome/free-regular-svg-icons'; const limit = 150; @@ -81,7 +110,11 @@ export default Vue.extend({ stats: [], deliverChart: null, inboxChart: null, - faTasks, faPaperPlane, faInbox, faStopwatch, faStopCircle, farPlayCircle, fasPlayCircle + jobs: [], + jobsLimit: 50, + domain: 'deliver', + state: 'delayed', + faTasks, faPaperPlane, faInbox, faStopwatch, faStopCircle, farPlayCircle, fasPlayCircle, faChartBar }; }, @@ -127,10 +160,22 @@ export default Vue.extend({ type: 'line', data: stats.map((x, i) => ({ x: i, y: x.deliver.delayed })) }]); - } + }, + + domain() { + this.jobs = []; + this.fetchJobs(); + }, + + state() { + this.jobs = []; + this.fetchJobs(); + }, }, mounted() { + this.fetchJobs(); + const chartOpts = id => ({ chart: { id, @@ -238,7 +283,17 @@ export default Vue.extend({ for (const stats of statsLog.reverse()) { this.onStats(stats); } - } + }, + + fetchJobs() { + this.$root.api('admin/queue/jobs', { + domain: this.domain, + state: this.state, + limit: this.jobsLimit + }).then(jobs => { + this.jobs = jobs; + }); + }, } }); @@ -249,4 +304,8 @@ export default Vue.extend({ min-height 200px !important margin 0 -8px +.xvvuvgsv + > b + margin-right 16px + diff --git a/src/server/api/endpoints/admin/queue/jobs.ts b/src/server/api/endpoints/admin/queue/jobs.ts new file mode 100644 index 0000000000..c2496d7ef7 --- /dev/null +++ b/src/server/api/endpoints/admin/queue/jobs.ts @@ -0,0 +1,40 @@ +import $ from 'cafy'; +import define from '../../../define'; +import { deliverQueue, inboxQueue } from '../../../../../queue'; + +export const meta = { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + params: { + domain: { + validator: $.str, + }, + + state: { + validator: $.str, + }, + + limit: { + validator: $.optional.num, + default: 50 + }, + } +}; + +export default define(meta, async (ps) => { + const queue = + ps.domain === 'deliver' ? deliverQueue : + ps.domain === 'inbox' ? inboxQueue : + null; + + const jobs = await queue.getJobs([ps.state], 0, ps.limit); + + return jobs.map(job => ({ + id: job.id, + data: job.data, + attempts: job.attemptsMade, + })); +});