@jsm-mit/rabbit-motoko-package 0.2.7 → 0.2.9
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.
|
@@ -2,10 +2,12 @@ import { Secp256k1KeyIdentity } from "@icp-sdk/core/identity/secp256k1";
|
|
|
2
2
|
import type { AddTaskArgs, ClaimTaskArgs, CompleteTaskArgs, Task } from "../declarations/rabbit-motoko-backend/rabbit-motoko-backend.did.js";
|
|
3
3
|
export declare class RabbitMotokoActor {
|
|
4
4
|
private readonly canisterId;
|
|
5
|
+
private readonly identity?;
|
|
5
6
|
private readonly host;
|
|
6
7
|
private actor;
|
|
7
8
|
private agent;
|
|
8
|
-
constructor(canisterId: string, identity?: Secp256k1KeyIdentity);
|
|
9
|
+
constructor(canisterId: string, identity?: Secp256k1KeyIdentity | undefined);
|
|
10
|
+
reinitilizeAgent(): void;
|
|
9
11
|
private initActor;
|
|
10
12
|
private setupAgent;
|
|
11
13
|
private runFunctionAndSyncTimeIfNecessaryAsyncUnsafe;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,KAAK,EAAY,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAS,IAAI,EAAE,MAAM,oEAAoE,CAAC;AAI9J,qBAAa,iBAAiB;IAKd,OAAO,CAAC,QAAQ,CAAC,UAAU;
|
|
1
|
+
{"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,KAAK,EAAY,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAS,IAAI,EAAE,MAAM,oEAAoE,CAAC;AAI9J,qBAAa,iBAAiB;IAKd,OAAO,CAAC,QAAQ,CAAC,UAAU;IAAU,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAJ3E,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;IAClD,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,KAAK,CAAa;gBAEG,UAAU,EAAE,MAAM,EAAmB,QAAQ,CAAC,EAAE,oBAAoB,YAAA;IAW1F,gBAAgB;IAQvB,OAAO,CAAC,SAAS;YAOH,UAAU;YAWV,4CAA4C;IA8B1D,OAAO,CAAC,kBAAkB;IAWb,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAajD,eAAe;IAIf,SAAS;IAItB;;OAEG;IACU,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAwB7F;;OAEG;IACU,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAwB/F;;OAEG;IACU,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAwBjG;;OAEG;IACU,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAwBrG"}
|
|
@@ -6,18 +6,22 @@ import { pigeon } from "@jsm-mit/pigeon-package";
|
|
|
6
6
|
export class RabbitMotokoActor {
|
|
7
7
|
constructor(canisterId, identity) {
|
|
8
8
|
this.canisterId = canisterId;
|
|
9
|
+
this.identity = identity;
|
|
9
10
|
this.host = "https://icp0.io";
|
|
10
11
|
// 1. Tworzymy agenta
|
|
11
|
-
this.
|
|
12
|
-
host: this.host,
|
|
13
|
-
ingressExpiryInMinutes: 1,
|
|
14
|
-
identity,
|
|
15
|
-
});
|
|
12
|
+
this.reinitilizeAgent();
|
|
16
13
|
// 2. Inicjalizujemy aktora
|
|
17
14
|
this.initActor();
|
|
18
15
|
// 3. Odpalamy asynchroniczną synchronizację
|
|
19
16
|
this.setupAgent();
|
|
20
17
|
}
|
|
18
|
+
reinitilizeAgent() {
|
|
19
|
+
this.agent = HttpAgent.createSync({
|
|
20
|
+
host: this.host,
|
|
21
|
+
ingressExpiryInMinutes: 1,
|
|
22
|
+
identity: this.identity
|
|
23
|
+
});
|
|
24
|
+
}
|
|
21
25
|
initActor() {
|
|
22
26
|
this.actor = Actor.createActor(idlFactory, {
|
|
23
27
|
agent: this.agent,
|
|
@@ -36,7 +40,7 @@ export class RabbitMotokoActor {
|
|
|
36
40
|
}
|
|
37
41
|
async runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(fn) {
|
|
38
42
|
try {
|
|
39
|
-
|
|
43
|
+
console.log("Running function...");
|
|
40
44
|
return fn();
|
|
41
45
|
}
|
|
42
46
|
catch (error) {
|
|
@@ -177,6 +181,7 @@ export class RabbitMotokoActor {
|
|
|
177
181
|
}
|
|
178
182
|
}
|
|
179
183
|
catch (err) {
|
|
184
|
+
console.log("catch getAvailableTaskIdsAsync catch");
|
|
180
185
|
logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
|
|
181
186
|
if (throwException) {
|
|
182
187
|
throw err;
|
|
@@ -7,6 +7,7 @@ export declare class RabbitTaskWorker {
|
|
|
7
7
|
private intervalId;
|
|
8
8
|
private isProcessing;
|
|
9
9
|
private readonly taskSubject;
|
|
10
|
+
private lastSuccessfulProcessTs;
|
|
10
11
|
get tasks$(): Observable<Task>;
|
|
11
12
|
constructor(channel: string, intervalMiliseconds: number, actor: RabbitMotokoActor);
|
|
12
13
|
private processQueue;
|
|
@@ -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;AAIlG,qBAAa,gBAAgB;
|
|
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;IAYrB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,KAAK;IAbjB,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuB;IAEnD,OAAO,CAAC,uBAAuB,CAAc;IAE7C,IAAW,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC,CAEpC;gBAGW,OAAO,EAAE,MAAM,EACf,mBAAmB,EAAE,MAAM,EAC3B,KAAK,EAAE,iBAAiB;YAItB,YAAY;IA+CnB,GAAG,IAAI,IAAI;IAWX,IAAI,IAAI,IAAI;CAQtB"}
|
|
@@ -13,15 +13,20 @@ export class RabbitTaskWorker {
|
|
|
13
13
|
this.intervalId = null;
|
|
14
14
|
this.isProcessing = false;
|
|
15
15
|
this.taskSubject = new Subject();
|
|
16
|
+
this.lastSuccessfulProcessTs = Date.now();
|
|
16
17
|
}
|
|
17
18
|
async processQueue() {
|
|
18
|
-
|
|
19
|
+
console.log('processQueue');
|
|
19
20
|
if (this.isProcessing)
|
|
20
21
|
return; // Zapobiega nakładaniu się wywołań
|
|
22
|
+
if (Date.now() - this.lastSuccessfulProcessTs > 5 * 60 * 1000) {
|
|
23
|
+
pigeon.reportUrgentAsyncSafe("No successful process in last 5 minutes", "");
|
|
24
|
+
this.actor.reinitilizeAgent();
|
|
25
|
+
}
|
|
21
26
|
try {
|
|
22
27
|
this.isProcessing = true;
|
|
23
28
|
const availableIds = await this.actor.getAvailableTaskIdsAsync(this.channel, false);
|
|
24
|
-
|
|
29
|
+
console.log(BetterJSON.stringify(availableIds));
|
|
25
30
|
if (!availableIds || availableIds.length === 0) {
|
|
26
31
|
return;
|
|
27
32
|
}
|
|
@@ -32,11 +37,12 @@ export class RabbitTaskWorker {
|
|
|
32
37
|
timeoutNanos: timeoutNanos
|
|
33
38
|
};
|
|
34
39
|
const task = await this.actor.claimTaskAsync(args, false);
|
|
35
|
-
|
|
40
|
+
console.log(BetterJSON.stringify(task));
|
|
36
41
|
if (task) {
|
|
37
42
|
this.taskSubject.next(task);
|
|
38
43
|
}
|
|
39
44
|
}
|
|
45
|
+
this.lastSuccessfulProcessTs = Date.now();
|
|
40
46
|
}
|
|
41
47
|
catch (err) {
|
|
42
48
|
pigeon.reportUrgentAsyncSafe("Unexpected error in processQueue", BetterJSON.stringify(err));
|