Sharkey/src/server/api/endpoints/admin/queue/jobs.ts

82 lines
1.8 KiB
TypeScript
Raw Normal View History

import { deliverQueue, inboxQueue, dbQueue, objectStorageQueue } from '@/queue/queues.js';
2019-03-15 13:48:17 +09:00
import $ from 'cafy';
import define from '../../../define.js';
2019-03-15 13:48:17 +09:00
export const meta = {
tags: ['admin'],
2020-02-15 21:33:32 +09:00
requireCredential: true as const,
2019-03-15 13:48:17 +09:00
requireModerator: true,
params: {
domain: {
validator: $.str.or(['deliver', 'inbox', 'db', 'objectStorage']),
2019-03-15 13:48:17 +09:00
},
state: {
validator: $.str.or(['active', 'waiting', 'delayed']),
2019-03-15 13:48:17 +09:00
},
limit: {
validator: $.optional.num,
default: 50
},
},
res: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'object' as const,
optional: false as const, nullable: false as const,
properties: {
id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
},
data: {
type: 'object' as const,
optional: false as const, nullable: false as const
},
attempts: {
type: 'number' as const,
optional: false as const, nullable: false as const
},
maxAttempts: {
type: 'number' as const,
optional: false as const, nullable: false as const
},
timestamp: {
type: 'number' as const,
optional: false as const, nullable: false as const
}
}
}
2019-03-15 13:48:17 +09:00
}
};
export default define(meta, async (ps) => {
const queue =
ps.domain === 'deliver' ? deliverQueue :
ps.domain === 'inbox' ? inboxQueue :
ps.domain === 'db' ? dbQueue :
ps.domain === 'objectStorage' ? objectStorageQueue :
null as never;
2019-03-15 13:48:17 +09:00
const jobs = await queue.getJobs([ps.state], 0, ps.limit!);
2019-03-15 13:48:17 +09:00
return jobs.map(job => {
const data = job.data;
delete data.content;
delete data.user;
return {
id: job.id,
data,
attempts: job.attemptsMade,
maxAttempts: job.opts ? job.opts.attempts : 0,
timestamp: job.timestamp,
};
});
2019-03-15 13:48:17 +09:00
});