From 5c0b86f6c0ffcaae7e6d1db17616a431ef82bca2 Mon Sep 17 00:00:00 2001 From: Cameron Crothers Date: Tue, 21 Feb 2017 14:23:53 +1100 Subject: [PATCH] Add finished function to Job --- bull/bull-tests.tsx | 15 +++++++++++++++ bull/index.d.ts | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/bull/bull-tests.tsx b/bull/bull-tests.tsx index 1d307fd31e..fcf339b3c3 100644 --- a/bull/bull-tests.tsx +++ b/bull/bull-tests.tsx @@ -98,3 +98,18 @@ videoQueue.process( ( job: VideoJob ) => { // don't forget to remove the done ca // If the job throws an unhandled exception it is also handled correctly throw new Error( 'some unexpected error' ); } ); + + +var addVideo1Job = videoQueue.add( { video: 'http://example.com/video1.mov' } ); + +addVideo1Job.then((video1Job) => { + // When job has successfully be placed in the queue the job is returned + // then wait for completion + return video1Job.finished(); +}) +.then(() => { + // video1Job completed successfully +}) +.catch((err) => { + // error +}); diff --git a/bull/index.d.ts b/bull/index.d.ts index c604fe25d6..51344c4bbc 100644 --- a/bull/index.d.ts +++ b/bull/index.d.ts @@ -47,6 +47,13 @@ declare module "bull" { * @returns {Promise} A promise that resolves when the job is scheduled for retry. */ retry(): Promise; + + /** + * Returns a promise the resolves when the job has been finished. + * TODO: Add a watchdog to check if the job has finished periodically. + * since pubsub does not give any guarantees. + */ + finished(): Promise; } export interface Backoff {