Add Jobs#reset.

This commit is contained in:
John-David Dalton
2014-05-02 19:38:10 -07:00
parent 9e4cc7fdbc
commit b97bbe0572

View File

@@ -433,6 +433,25 @@ function Job(properties) {
Job.prototype = _.create(EventEmitter.prototype);
/**
* Resets the job.
*
* @memberOf Job
* @param {Function} callback The function called once the job is reset.
* @param {Object} Returns the job instance.
*/
Job.prototype.reset = function(callback) {
if (this.running) {
return this.stop(_.bind(this.reset, this));
}
this.attempts = 0;
this.failed = false;
this.id = this.result = this.url = null;
_.defer(callback);
return this;
};
/**
* Restarts the job.
*
@@ -580,11 +599,7 @@ function Tunnel(properties) {
this.on('stop', function() {
completed = 0;
success = true;
_.each(all, function(job) {
job.attempts = 0;
job.failed = false;
job.id = job.result = job.url = null;
});
_.invoke(all, 'reset');
});
this.jobs = {'active': active, 'all': all, 'queue': queue };