Skip to content

Commit 12a7267

Browse files
authored
Merge pull request #3 from hopdrive/feature/delete-single-job
Delete jobs by id and all failed jobs
2 parents ea77439 + 1615851 commit 12a7267

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

Models/Queue.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,44 @@ export class Queue {
566566
}
567567
}
568568

569+
/**
570+
* Delete a job from the queue.
571+
*
572+
* @param jobId {string} - Unique id associated with job.
573+
*
574+
*/
575+
576+
deleteJob(jobId) {
577+
this.realm.write(() => {
578+
let job = this.realm.objects('Job').filtered('id == "' + jobId + '"');
579+
580+
if (job.length) {
581+
this.realm.delete(job);
582+
} else {
583+
throw new Error('Job ' + jobId + ' does not exist.');
584+
}
585+
});
586+
}
587+
588+
/**
589+
*
590+
* Delete all failed jobs from the queue.
591+
*
592+
*
593+
*/
594+
595+
deleteAllFailedJobs() {
596+
this.realm.write(() => {
597+
let jobs = Array.from(this.realm.objects('Job')
598+
.filtered('failed != null'));
599+
600+
if (jobs.length) {
601+
this.realm.delete(jobs);
602+
}
603+
});
604+
}
605+
606+
569607
/**
570608
*
571609
* Delete jobs in the queue.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hopdrive/react-native-queue",
3-
"version": "2.3.1",
3+
"version": "2.4.0",
44
"description": "A React Native Job Queue",
55
"main": "index.js",
66
"publishConfig": {

0 commit comments

Comments
 (0)