Skip to content

Commit

Permalink
added state-based fetch api
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed Apr 27, 2017
1 parent 4549af3 commit 6395db9
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class Manager extends EventEmitter {
this.cancelJobCommand = plans.cancelJob(config.schema);
this.failJobCommand = plans.failJob(config.schema);

this.offFail = name => this.unsubscribe(name + failedJobSuffix);
this.offExpire = name => this.unsubscribe(name + expiredJobSuffix);
this.offComplete = name => this.unsubscribe(name + completedJobSuffix);

this.fetchFailed = name => this.fetch(name + failedJobSuffix);
this.fetchExpired = name => this.fetch(name + expiredJobSuffix);
this.fetchCompleted = name => this.fetch(name + completedJobSuffix);

this.functions = [
this.fetch,
this.complete,
Expand All @@ -46,7 +54,10 @@ class Manager extends EventEmitter {
this.onExpire,
this.offExpire,
this.onFail,
this.offFail
this.offFail,
this.fetchFailed,
this.fetchExpired,
this.fetchCompleted
];
}

Expand Down Expand Up @@ -76,18 +87,6 @@ class Manager extends EventEmitter {
.then(({options, callback}) => this.watch(name + expiredJobSuffix, options, (job, done) => callback(job.data, done)));
}

offExpire(name){
return this.unsubscribe(name + expiredJobSuffix);
}

offComplete(name){
return this.unsubscribe(name + completedJobSuffix);
}

offFail(name){
return this.unsubscribe(name + failedJobSuffix);
}

onComplete(name, ...args) {
return Attorney.checkSubscribeArgs(name, args)
.then(({options, callback}) => this.watch(name + completedJobSuffix, options, callback));
Expand Down

0 comments on commit 6395db9

Please sign in to comment.