Commit e4234270 authored by nanahira's avatar nanahira

update queue

parent 4f02a00c
......@@ -23,9 +23,9 @@
"typescript": "^4.8.3"
},
"peerDependencies": {
"@nestjs/common": "^9.1.2",
"@nestjs/core": "^9.4.2",
"aragami": "^1.1.8",
"@nestjs/common": "^9.1.2 || ^10.0.0",
"@nestjs/core": "^9.4.2 || ^10.0.0",
"aragami": "^1.2.0",
"rxjs": "^7.8.1"
}
},
......@@ -1092,9 +1092,9 @@
}
},
"node_modules/@nanahira/redlock": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@nanahira/redlock/-/redlock-1.0.0.tgz",
"integrity": "sha512-kf48X8tSbZm1DQT3Aj3B/Fza+L9toi5+j47BX9WJ9hIqyuCDRWMC2wQOJB1XAcOFZ+FGrfAjTa21bdTEuVlYeQ==",
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@nanahira/redlock/-/redlock-1.0.1.tgz",
"integrity": "sha512-gpHYiz0P57SJDNsgr/sh/1Qn12fbdfVx1AlWWbfd56M0PWPzewqwJhY3U6wInvxC0yX6ynTFioqnvJ8vNGJIDw==",
"peer": true,
"dependencies": {
"node-abort-controller": "^3.0.1"
......@@ -1653,12 +1653,12 @@
}
},
"node_modules/aragami": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/aragami/-/aragami-1.1.8.tgz",
"integrity": "sha512-kHwOawwEFfEyxAt6/dRm5YORgIfFtZl2b/TFoZx0LxQzP3uqNgf1tkbfjLEVi5DI+nRAe6iDd+43bn1c5ZNXCg==",
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aragami/-/aragami-1.2.0.tgz",
"integrity": "sha512-uTRn34cF8jpmxsjjbDCIlbpERJuZmAcGZHfasFEfV1mt/zDL+pEqheZ9j18VCt0yOlJTf9VUHBY7xES6Zyv3ag==",
"peer": true,
"dependencies": {
"@nanahira/redlock": "^1.0.0",
"@nanahira/redlock": "^1.0.1",
"better-lock": "^2.0.3",
"class-transformer": "^0.5.1",
"encoded-buffer": "^0.2.6",
......@@ -3915,9 +3915,9 @@
"dev": true
},
"node_modules/node-abort-controller": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.0.1.tgz",
"integrity": "sha512-/ujIVxthRs+7q6hsdjHMaj8hRG9NuWmwrz+JdRwZ14jdFoKSkm+vDsCbF9PLpnSqjaWQJuTmVtcWHNLr+vrOFw==",
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.1.1.tgz",
"integrity": "sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==",
"peer": true
},
"node_modules/node-fetch": {
......@@ -5990,9 +5990,9 @@
"peer": true
},
"@nanahira/redlock": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@nanahira/redlock/-/redlock-1.0.0.tgz",
"integrity": "sha512-kf48X8tSbZm1DQT3Aj3B/Fza+L9toi5+j47BX9WJ9hIqyuCDRWMC2wQOJB1XAcOFZ+FGrfAjTa21bdTEuVlYeQ==",
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@nanahira/redlock/-/redlock-1.0.1.tgz",
"integrity": "sha512-gpHYiz0P57SJDNsgr/sh/1Qn12fbdfVx1AlWWbfd56M0PWPzewqwJhY3U6wInvxC0yX6ynTFioqnvJ8vNGJIDw==",
"peer": true,
"requires": {
"node-abort-controller": "^3.0.1"
......@@ -6379,12 +6379,12 @@
}
},
"aragami": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/aragami/-/aragami-1.1.8.tgz",
"integrity": "sha512-kHwOawwEFfEyxAt6/dRm5YORgIfFtZl2b/TFoZx0LxQzP3uqNgf1tkbfjLEVi5DI+nRAe6iDd+43bn1c5ZNXCg==",
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aragami/-/aragami-1.2.0.tgz",
"integrity": "sha512-uTRn34cF8jpmxsjjbDCIlbpERJuZmAcGZHfasFEfV1mt/zDL+pEqheZ9j18VCt0yOlJTf9VUHBY7xES6Zyv3ag==",
"peer": true,
"requires": {
"@nanahira/redlock": "^1.0.0",
"@nanahira/redlock": "^1.0.1",
"better-lock": "^2.0.3",
"class-transformer": "^0.5.1",
"encoded-buffer": "^0.2.6",
......@@ -8103,9 +8103,9 @@
"dev": true
},
"node-abort-controller": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.0.1.tgz",
"integrity": "sha512-/ujIVxthRs+7q6hsdjHMaj8hRG9NuWmwrz+JdRwZ14jdFoKSkm+vDsCbF9PLpnSqjaWQJuTmVtcWHNLr+vrOFw==",
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.1.1.tgz",
"integrity": "sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==",
"peer": true
},
"node-fetch": {
......
......@@ -55,7 +55,7 @@
"peerDependencies": {
"@nestjs/common": "^9.1.2 || ^10.0.0",
"@nestjs/core": "^9.4.2 || ^10.0.0",
"aragami": "^1.1.8",
"aragami": "^1.2.0",
"rxjs": "^7.8.1"
}
}
......@@ -24,6 +24,11 @@ export class _QueueRunner<T> {
aragami: Aragami;
async onApplicationBootstrap() {
await this.aragami.queueResumeAll(
this._queueClass,
this._queueRunnerOptions.key,
true,
);
if (this._queueRunnerOptions.logTask) {
this.logger.log(`Starting ${this._maxConcurrency} workers`);
}
......@@ -52,33 +57,35 @@ export class _QueueRunner<T> {
while (!this._quit) {
logger.log('Looping');
try {
const task: T = await this.aragami.queueGatherBlocking(
await this.aragami.runQueueOnce(
this._queueClass,
async (task) => {
if (this._queueRunnerOptions.logTask) {
logger.log(`Got task: ${JSON.stringify(task)}`);
}
try {
await this.runTask(task, i);
} catch (e) {
logger.error(`Task failed: ${e}`);
if (
this._queueRunnerOptions.retry &&
(!task['__retry'] ||
task['__retry'] < this._queueRunnerOptions.retry)
) {
logger.log(`Retrying task: ${JSON.stringify(task)}`);
if (this._queueRunnerOptions.retry > 0) {
task['__retry'] = (task['__retry'] || 0) + 1;
}
await this.aragami.queueAdd(task, {
key: this._queueKey,
prior: true,
});
}
}
},
this._queueKey,
);
if (!task) continue;
if (this._queueRunnerOptions.logTask) {
logger.log(`Got task: ${JSON.stringify(task)}`);
}
try {
await this.runTask(task, i);
} catch (e) {
logger.error(`Task failed: ${e}`);
if (
this._queueRunnerOptions.retry &&
(!task['__retry'] ||
task['__retry'] < this._queueRunnerOptions.retry)
) {
logger.log(`Retrying task: ${JSON.stringify(task)}`);
if (this._queueRunnerOptions.retry > 0) {
task['__retry'] = (task['__retry'] || 0) + 1;
}
await this.aragami.queueAdd(task, {
key: this._queueKey,
prior: true,
});
}
}
//
} catch (e) {
logger.error(`Loop failed: ${e}`);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment