@jsm-mit/rabbit-motoko-package 0.2.8 → 0.2.10
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;IAK1F,gBAAgB;IAUvB,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,17 +6,18 @@ 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
|
+
this.reinitilizeAgent();
|
|
12
|
+
this.setupAgent();
|
|
13
|
+
}
|
|
14
|
+
reinitilizeAgent() {
|
|
11
15
|
this.agent = HttpAgent.createSync({
|
|
12
16
|
host: this.host,
|
|
13
17
|
ingressExpiryInMinutes: 1,
|
|
14
|
-
identity
|
|
18
|
+
identity: this.identity
|
|
15
19
|
});
|
|
16
|
-
// 2. Inicjalizujemy aktora
|
|
17
20
|
this.initActor();
|
|
18
|
-
// 3. Odpalamy asynchroniczną synchronizację
|
|
19
|
-
this.setupAgent();
|
|
20
21
|
}
|
|
21
22
|
initActor() {
|
|
22
23
|
this.actor = Actor.createActor(idlFactory, {
|
|
@@ -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;IAkDnB,GAAG,IAAI,IAAI;IAWX,IAAI,IAAI,IAAI;CAQtB"}
|
|
@@ -13,11 +13,18 @@ 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
|
+
const duration = Date.now() - this.lastSuccessfulProcessTs;
|
|
23
|
+
console.log(duration);
|
|
24
|
+
if (duration > 5 * 60 * 1000) {
|
|
25
|
+
pigeon.reportUrgentAsyncSafe("No successful process in last 5 minutes", "");
|
|
26
|
+
this.actor.reinitilizeAgent();
|
|
27
|
+
}
|
|
21
28
|
try {
|
|
22
29
|
this.isProcessing = true;
|
|
23
30
|
const availableIds = await this.actor.getAvailableTaskIdsAsync(this.channel, false);
|
|
@@ -37,6 +44,7 @@ export class RabbitTaskWorker {
|
|
|
37
44
|
this.taskSubject.next(task);
|
|
38
45
|
}
|
|
39
46
|
}
|
|
47
|
+
this.lastSuccessfulProcessTs = Date.now();
|
|
40
48
|
}
|
|
41
49
|
catch (err) {
|
|
42
50
|
pigeon.reportUrgentAsyncSafe("Unexpected error in processQueue", BetterJSON.stringify(err));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsm-mit/rabbit-motoko-package",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Wrapper TypeScript package for Rabbit Motoko Canister.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@icp-sdk/core": "^5.2.0",
|
|
30
|
-
"@jsm-mit/pigeon-package": "^0.5.
|
|
30
|
+
"@jsm-mit/pigeon-package": "^0.5.2",
|
|
31
31
|
"@jsm-mit/utils-package": "^0.2.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|