File tree 3 files changed +20
-24
lines changed
3 files changed +20
-24
lines changed Original file line number Diff line number Diff line change @@ -739,22 +739,21 @@ Disables the `job`. Upcoming runs won't execute.
739
739
740
740
Enables the ` job ` if it got disabled before. Upcoming runs will execute.
741
741
742
- ### touch(callback )
742
+ ### touch()
743
743
744
744
Resets the lock on the job. Useful to indicate that the job hasn't timed out
745
- when you have very long running jobs.
745
+ when you have very long running jobs. The call returns a promise that resolves
746
+ when the job's lock has been renewed.
746
747
747
748
``` js
748
749
agenda .define (' super long job' , (job , done ) => {
749
- doSomeLongTask (() => {
750
- job .touch (() => {
751
- doAnotherLongTask (() => {
752
- job .touch (() => {
753
- finishOurLongTasks (done);
754
- });
755
- });
756
- });
757
- });
750
+ (async () => {
751
+ await doSomeLongTask ();
752
+ await job .touch ();
753
+ await doAnotherLongTask ();
754
+ await job .touch ();
755
+ await finishOurLongTasks ();
756
+ })().then (done, done);
758
757
});
759
758
```
760
759
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ const noCallback = require ( '../no-callback' ) ;
4
+
3
5
/**
4
6
* Updates "lockedAt" time so the job does not get picked up again
5
7
* @name Job#touch
6
8
* @function
7
- * @param {Function } cb called when job "touch" fails or passes
8
9
* @returns {undefined }
9
10
*/
10
- module . exports = function ( cb ) {
11
+ module . exports = async function ( ) {
12
+ // eslint-disable-next-line prefer-rest-params
13
+ noCallback ( arguments ) ;
11
14
this . attrs . lockedAt = new Date ( ) ;
12
- this . save ( cb ) ;
15
+ return this . save ( ) ;
13
16
} ;
Original file line number Diff line number Diff line change @@ -349,18 +349,12 @@ describe('Job', () => {
349
349
} ) ;
350
350
351
351
describe ( 'touch' , ( ) => {
352
- it ( 'extends the lock lifetime' , done => {
352
+ it ( 'extends the lock lifetime' , async ( ) => {
353
353
const lockedAt = new Date ( ) ;
354
354
const job = new Job ( { agenda, name : 'some job' , lockedAt} ) ;
355
- job . save = function ( cb ) {
356
- cb ( ) ;
357
- } ;
358
- setTimeout ( ( ) => {
359
- job . touch ( ( ) => {
360
- expect ( job . attrs . lockedAt ) . to . be . greaterThan ( lockedAt ) ;
361
- done ( ) ;
362
- } ) ;
363
- } , 2 ) ;
355
+ await delay ( 2 ) ;
356
+ await job . touch ( ) ;
357
+ expect ( job . attrs . lockedAt ) . to . be . greaterThan ( lockedAt ) ;
364
358
} ) ;
365
359
} ) ;
366
360
You can’t perform that action at this time.
0 commit comments