Add finished function to Job

This commit is contained in:
Cameron Crothers
2017-02-21 14:23:53 +11:00
parent 506f839726
commit 5c0b86f6c0
2 changed files with 22 additions and 0 deletions

View File

@@ -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
});

7
bull/index.d.ts vendored
View File

@@ -47,6 +47,13 @@ declare module "bull" {
* @returns {Promise} A promise that resolves when the job is scheduled for retry.
*/
retry(): Promise<void>;
/**
* 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<void>;
}
export interface Backoff {