@jsm-mit/rabbit-motoko-package 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbit-task-worker.d.ts","sourceRoot":"","sources":["../src/rabbit-task-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAsB,KAAK,IAAI,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"rabbit-task-worker.d.ts","sourceRoot":"","sources":["../src/rabbit-task-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAsB,KAAK,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAIlG,qBAAa,gBAAgB;IAUrB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,KAAK;IAXjB,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuB;IAEnD,IAAW,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC,CAEpC;gBAGW,OAAO,EAAE,MAAM,EACf,mBAAmB,EAAE,MAAM,EAC3B,KAAK,EAAE,iBAAiB;YAItB,YAAY;IAwCnB,GAAG,IAAI,IAAI;IAWX,IAAI,IAAI,IAAI;CAQtB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Observable, Subject } from 'rxjs';
|
|
2
2
|
import { RabbitMotokoActor } from '@jsm-mit/rabbit-motoko-package';
|
|
3
3
|
import { BetterJSON, logErrorLocallyAndPublishOnErrorSubject } from '@jsm-mit/utils-package';
|
|
4
|
+
import { pigeon } from '@jsm-mit/pigeon-package';
|
|
4
5
|
export class RabbitTaskWorker {
|
|
5
6
|
get tasks$() {
|
|
6
7
|
return this.taskSubject.asObservable();
|
|
@@ -14,25 +15,35 @@ export class RabbitTaskWorker {
|
|
|
14
15
|
this.taskSubject = new Subject();
|
|
15
16
|
}
|
|
16
17
|
async processQueue() {
|
|
18
|
+
pigeon.debugLog('processQueue');
|
|
17
19
|
if (this.isProcessing)
|
|
18
20
|
return; // Zapobiega nakładaniu się wywołań
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.
|
|
21
|
+
try {
|
|
22
|
+
this.isProcessing = true;
|
|
23
|
+
const availableIds = await this.actor.getAvailableTaskIdsAsync(this.channel, false);
|
|
24
|
+
pigeon.debugLog(BetterJSON.stringify(availableIds));
|
|
25
|
+
if (!availableIds || availableIds.length === 0) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const timeoutNanos = BigInt(5 * 60 * 1000000000);
|
|
29
|
+
for (const taskId of availableIds) {
|
|
30
|
+
const args = {
|
|
31
|
+
id: taskId,
|
|
32
|
+
timeoutNanos: timeoutNanos
|
|
33
|
+
};
|
|
34
|
+
const task = await this.actor.claimTaskAsync(args, false);
|
|
35
|
+
pigeon.debugLog(BetterJSON.stringify(task));
|
|
36
|
+
if (task) {
|
|
37
|
+
this.taskSubject.next(task);
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
|
-
|
|
41
|
+
catch (err) {
|
|
42
|
+
pigeon.reportUrgentAsyncSafe("Unexpected error in processQueue", BetterJSON.stringify(err));
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
this.isProcessing = false;
|
|
46
|
+
}
|
|
36
47
|
}
|
|
37
48
|
run() {
|
|
38
49
|
if (this.intervalId)
|