Merge pull request #14751 from JProgrammer/bull-finished

Add finished function to Job
This commit is contained in:
Mine Starks
2017-03-08 15:36:07 -08:00
committed by GitHub
2 changed files with 24 additions and 2 deletions
+15
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
});
+9 -2
View File
@@ -1,6 +1,6 @@
// Type definitions for bull 1.0.0
// Type definitions for bull 2.1.2
// Project: https://github.com/OptimalBits/bull
// Definitions by: Bruno Grieder <https://github.com/bgrieder>
// Definitions by: Bruno Grieder <https://github.com/bgrieder>, Cameron Crothers <https://github.com/JProgrammer>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="redis" />
@@ -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 {