Skip to content

Commit bf26cad

Browse files
authored
Merge pull request #46 from SimonErm/feature/retry+remove_jobs
Feature/retry+remove jobs
2 parents 4c75010 + 169bbfc commit bf26cad

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

example/App.tsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,34 @@ export default class App extends React.Component<IAppProps, IAppState> {
5656
<Button
5757
title='cancel Job'
5858
onPress={() => {
59-
if(this.state.jobId){
60-
queue.cancelJob(this.state.jobId, {message: 'Canceled'})
61-
} else {
62-
console.log("no job running");
63-
}
59+
if (this.state.jobId) {
60+
queue.cancelJob(this.state.jobId, { message: 'Canceled' })
61+
} else {
62+
console.log("no job running");
63+
}
64+
}}
65+
/>
66+
<Button
67+
title='remove failed Jobs'
68+
onPress={async () => {
69+
let jobs = await queue.getJobs();
70+
let jobRemovals = jobs.filter(job => job.failed !== '').map(async job => await queue.removeJob(job))
71+
await Promise.all(jobRemovals)
72+
}}
73+
/>
74+
<Button
75+
title='requeue failed Jobs'
76+
onPress={async () => {
77+
let jobs = await queue.getJobs();
78+
let jobRequeues = jobs.filter(job => job.failed !== '').map(async job => await queue.requeueJob(job))
79+
await Promise.all(jobRequeues)
80+
}}
81+
/>
82+
<Button
83+
title='getJobs'
84+
onPress={async () => {
85+
let jobs = await queue.getJobs();
86+
console.log(jobs)
6487
}}
6588
/>
6689
<Button

src/Queue.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ export class Queue {
9797
async getJobs() {
9898
return await this.jobStore.getJobs();
9999
}
100+
/**
101+
* @param job the job to be deleted
102+
*/
103+
async removeJob(job: RawJob) {
104+
return await this.jobStore.removeJob(job);
105+
}
106+
/**
107+
* @param job the job which should be requeued
108+
*/
109+
async requeueJob(job: RawJob) {
110+
return await this.jobStore.updateJob({ ...job, failed: '' });
111+
}
100112

101113
configure(options: QueueOptions) {
102114
const {

0 commit comments

Comments
 (0)