File tree Expand file tree Collapse file tree 3 files changed +10
-11
lines changed
Expand file tree Collapse file tree 3 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -19,20 +19,20 @@ class RedisExclusiveTask {
1919
2020 extendAndRun ( lock ) {
2121 return lock . extend ( this . interval * 2 ) . then ( ( ) => this . task ( ) ) . delay ( this . interval ) . then ( ( ) => this . extendAndRun ( lock ) ) // recurse
22- . catch ( ( ) => this . log . info ( `@RedisExclusiveTask(${ this . taskName } ): Unable to extend lock` ) ) . finally ( ( ) => this . log . warn ( `@RedisExclusiveTask(${ this . taskName } ): Leaving extendAndUpdate` ) ) ;
22+ . catch ( ( ) => RedisExclusiveTask . log . info ( `@RedisExclusiveTask(${ this . taskName } ): Unable to extend lock` ) ) . finally ( ( ) => RedisExclusiveTask . log . warn ( `@RedisExclusiveTask(${ this . taskName } ): Leaving extendAndUpdate` ) ) ;
2323 // only on error bail out
2424 }
2525
2626 lockAndRun ( ) {
27- return this . redlock . lock ( `${ this . taskName } :run` , this . interval * 2 ) . then ( lock => {
28- log . info ( `@RedisExclusiveTask(${ this . taskName } ): I have the lock!` ) ;
27+ return RedisExclusiveTask . redlockInstance . lock ( `${ this . taskName } :run` , this . interval * 2 ) . then ( lock => {
28+ RedisExclusiveTask . log . info ( `@RedisExclusiveTask(${ this . taskName } ): I have the lock!` ) ;
2929 return this . extendAndRun ( lock ) ;
3030 } ) . catch ( ( ) => { } ) ;
3131 }
3232
3333 static configure ( clients , log = console ) {
3434 this . log = log ;
35- this . redlock = new _redlock2 . default ( clients , { retryCount : 0 } ) ;
35+ this . redlockInstance = new _redlock2 . default ( clients , { retryCount : 0 } ) ;
3636 }
3737
3838 static run ( taskName , task , interval ) {
Original file line number Diff line number Diff line change 11{
22 "name" : " redis-exclusive-task" ,
3- "version" : " 0.1.0" ,
4- "private" : true ,
3+ "version" : " 0.1.1" ,
54 "scripts" : {
65 "build" : " babel src/index.js --out-file dist/index.js --presets node6"
76 },
Original file line number Diff line number Diff line change @@ -16,23 +16,23 @@ export default class RedisExclusiveTask {
1616 . then ( ( ) => this . task ( ) )
1717 . delay ( this . interval )
1818 . then ( ( ) => this . extendAndRun ( lock ) ) // recurse
19- . catch ( ( ) => this . log . info ( `@RedisExclusiveTask(${ this . taskName } ): Unable to extend lock` ) )
20- . finally ( ( ) => this . log . warn ( `@RedisExclusiveTask(${ this . taskName } ): Leaving extendAndUpdate` ) ) ;
19+ . catch ( ( ) => RedisExclusiveTask . log . info ( `@RedisExclusiveTask(${ this . taskName } ): Unable to extend lock` ) )
20+ . finally ( ( ) => RedisExclusiveTask . log . warn ( `@RedisExclusiveTask(${ this . taskName } ): Leaving extendAndUpdate` ) ) ;
2121 // only on error bail out
2222 }
2323
2424 lockAndRun ( ) {
25- return this . redlock . lock ( `${ this . taskName } :run` , this . interval * 2 )
25+ return RedisExclusiveTask . redlockInstance . lock ( `${ this . taskName } :run` , this . interval * 2 )
2626 . then ( ( lock ) => {
27- log . info ( `@RedisExclusiveTask(${ this . taskName } ): I have the lock!` ) ;
27+ RedisExclusiveTask . log . info ( `@RedisExclusiveTask(${ this . taskName } ): I have the lock!` ) ;
2828 return this . extendAndRun ( lock ) ;
2929 } )
3030 . catch ( ( ) => { } ) ;
3131 }
3232
3333 static configure ( clients , log = console ) {
3434 this . log = log ;
35- this . redlock = new Redlock ( clients , { retryCount : 0 } ) ;
35+ this . redlockInstance = new Redlock ( clients , { retryCount : 0 } ) ;
3636 }
3737
3838 static run ( taskName , task , interval ) {
You can’t perform that action at this time.
0 commit comments