Skip to content

Commit

Permalink
feat: allows to print export job queue and cancel job
Browse files Browse the repository at this point in the history
  • Loading branch information
uffy committed May 31, 2024
1 parent 2011ebf commit f7a2b44
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/next-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ AV.Cloud.define('dailyPushStatsToSlack', () => dailyPushStatsToSlack())
AV.Cloud.define('weeklyPushStatsToSlack', () => weeklyPushStatsToSlack())
AV.Cloud.define('monthlyPushStatsToSlack', () => monthlyPushStatsToSlack())

const { cancelTicketExportJob } = require('../next/api/dist/ticket/export')
AV.Cloud.define('removeExportJob', (req) => {
if (!req.params.jobId) {
console.error('Cloud Function - removeExportJob: missing jobId')
return
}

cancelTicketExportJob(req.params.jobId)
})

AV.Cloud.onLogin((request) => {
if (request.object.get('inactive')) {
throw new AV.Cloud.Error(
Expand Down
29 changes: 29 additions & 0 deletions next/api/src/ticket/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,32 @@ export async function createTicketExportJob(jobData: Omit<JobData, 'date' | 'tas
taskId: task.id,
});
}

export async function cancelTicketExportJob(jobId: string) {
const job = await queue.getJob(jobId)
if (!job) {
console.log(`cancelTicketExportJob: job ${jobId} not found`)
return
}

console.log(`cancelTicketExportJob: canceling job ${jobId}`)

await job.remove()
const task = await ExportTicketTask.find(job.data.taskId, { useMasterKey: true });
if (task) {
await task.update(
{
status: 'canceled',
},
{ useMasterKey: true }
);
}
}

export async function getTicketExportJobInfo() {
const jobs = await queue.getJobs(['waiting', 'active', 'delayed', 'completed', 'failed'])
console.log('getTicketExportJobInfo')
jobs.map(job => (
console.log(`job ${job.id} ${new Date(job.timestamp)}: ${job.data.taskId} ${job.data.date} ${job.data.userId}`)
))
}

0 comments on commit f7a2b44

Please sign in to comment.