Skip to content

Commit 19ca0b8

Browse files
authored
Merge pull request #2 from sloops77/011
011
2 parents e5d160a + cc10844 commit 19ca0b8

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

dist/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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) {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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
},

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)