@jsm-mit/rabbit-motoko-package 0.2.17 → 0.2.18
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.
|
@@ -13,23 +13,10 @@ export declare class RabbitMotokoActor {
|
|
|
13
13
|
private runFunctionAndSyncTimeIfNecessaryAsyncUnsafe;
|
|
14
14
|
private handleResultErrors;
|
|
15
15
|
syncTimeAsync(throwError: boolean): Promise<void>;
|
|
16
|
-
|
|
17
|
-
testError(): Promise<import("../declarations/rabbit-motoko-backend/rabbit-motoko-backend.did.js").Result>;
|
|
18
|
-
/**
|
|
19
|
-
* Adds a new task to the queue.
|
|
20
|
-
*/
|
|
16
|
+
private executeFunction;
|
|
21
17
|
addTaskAsync(args: AddTaskArgs, throwException: boolean): Promise<bigint | null>;
|
|
22
|
-
/**
|
|
23
|
-
* Claims a task for a specific worker.
|
|
24
|
-
*/
|
|
25
18
|
claimTaskAsync(args: ClaimTaskArgs, throwException: boolean): Promise<Task | null>;
|
|
26
|
-
/**
|
|
27
|
-
* Completes a previously claimed task.
|
|
28
|
-
*/
|
|
29
19
|
completeTaskAsync(args: CompleteTaskArgs, throwException: boolean): Promise<boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* Fetches IDs of tasks available in a specific channel.
|
|
32
|
-
*/
|
|
33
20
|
getAvailableTaskIdsAsync(channel: string, throwException: boolean): Promise<bigint[]>;
|
|
34
21
|
}
|
|
35
22
|
//# sourceMappingURL=rabbit-motoko-actor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"AACA,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,iBAAiB;IAYxB,OAAO,CAAC,SAAS;YAOH,UAAU;YASV,4CAA4C;IAwB1D,OAAO,CAAC,kBAAkB;IAQb,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YAQhD,eAAe;IA0BhB,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAWhF,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAWlF,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAWpF,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAUrG"}
|
|
@@ -28,7 +28,6 @@ export class RabbitMotokoActor {
|
|
|
28
28
|
}
|
|
29
29
|
async setupAgent() {
|
|
30
30
|
try {
|
|
31
|
-
// Synchronizacja czasu z siecią IC - rozwiązuje błąd "certificate is still too far in the future"
|
|
32
31
|
await this.agent.syncTime();
|
|
33
32
|
console.log("✅ Agent IC zsynchronizowany pomyślnie.");
|
|
34
33
|
}
|
|
@@ -42,9 +41,9 @@ export class RabbitMotokoActor {
|
|
|
42
41
|
}
|
|
43
42
|
catch (error) {
|
|
44
43
|
const errorMsg = BetterJSON.stringify(error);
|
|
45
|
-
pigeon.debugEmailAsyncSafe("Problem at runFunctionAndSyncTimeIfNecessaryAsyncUnsafe", "
|
|
44
|
+
pigeon.debugEmailAsyncSafe("Problem at runFunctionAndSyncTimeIfNecessaryAsyncUnsafe", "RabbitMotokoActor", [], errorMsg);
|
|
46
45
|
if (errorMsg.includes("certificate") || errorMsg.includes("TrustError") || errorMsg.includes("ingress_expiry")) {
|
|
47
|
-
console.warn("⚠️ Wykryto problem z
|
|
46
|
+
console.warn("⚠️ Wykryto problem z czasem. Próbuję synchronizacji...");
|
|
48
47
|
await this.syncTimeAsync(false);
|
|
49
48
|
try {
|
|
50
49
|
return await fnAsync();
|
|
@@ -55,7 +54,6 @@ export class RabbitMotokoActor {
|
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
else {
|
|
58
|
-
console.error(`Error at runFunctionAndSyncTimeIfNecessaryAsyncUnsafe: ${errorMsg}`);
|
|
59
57
|
throw error;
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -64,128 +62,44 @@ export class RabbitMotokoActor {
|
|
|
64
62
|
pigeon.debugEmailAsyncSafe("debug", functionName, params, BetterJSON.stringify(error));
|
|
65
63
|
const errorKey = Object.keys(error)[0];
|
|
66
64
|
const errorMessage = error[errorKey];
|
|
67
|
-
return {
|
|
68
|
-
errorKey,
|
|
69
|
-
errorMessage
|
|
70
|
-
};
|
|
65
|
+
return { errorKey, errorMessage };
|
|
71
66
|
}
|
|
72
67
|
async syncTimeAsync(throwError) {
|
|
73
68
|
try {
|
|
74
69
|
await this.agent.syncTime();
|
|
75
|
-
console.log("🔄 Czas agenta został zsynchronizowany ponownie.");
|
|
76
70
|
}
|
|
77
71
|
catch (err) {
|
|
78
|
-
|
|
79
|
-
if (throwError) {
|
|
72
|
+
if (throwError)
|
|
80
73
|
throw err;
|
|
81
|
-
}
|
|
82
74
|
}
|
|
83
75
|
}
|
|
84
|
-
async
|
|
85
|
-
return this.actor.testErrWithText();
|
|
86
|
-
}
|
|
87
|
-
async testError() {
|
|
88
|
-
return this.actor.testError();
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Adds a new task to the queue.
|
|
92
|
-
*/
|
|
93
|
-
async addTaskAsync(args, throwException) {
|
|
94
|
-
const errorMessage = "Network error: add task failed";
|
|
76
|
+
async executeFunction(fnAsync, errorMessage, functionName, params, defaultValue, throwException) {
|
|
95
77
|
try {
|
|
96
|
-
const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(
|
|
78
|
+
const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(fnAsync);
|
|
97
79
|
if ('ok' in result) {
|
|
98
80
|
return result.ok;
|
|
99
81
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
82
|
+
this.handleResultErrors(functionName, params, result.err);
|
|
83
|
+
return defaultValue;
|
|
104
84
|
}
|
|
105
85
|
catch (err) {
|
|
106
86
|
logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
|
|
107
|
-
if (throwException)
|
|
87
|
+
if (throwException)
|
|
108
88
|
throw err;
|
|
109
|
-
|
|
110
|
-
else {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
89
|
+
return defaultValue;
|
|
113
90
|
}
|
|
114
91
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
92
|
+
// --- Public Actor Methods ---
|
|
93
|
+
async addTaskAsync(args, throwException) {
|
|
94
|
+
return await this.executeFunction(() => this.actor.addTask(args), "Network error: add task failed", "addTaskAsync", [args, throwException], null, throwException);
|
|
95
|
+
}
|
|
118
96
|
async claimTaskAsync(args, throwException) {
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(() => this.actor.claimTask(args));
|
|
122
|
-
if ('ok' in result) {
|
|
123
|
-
return result.ok;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
this.handleResultErrors("claimTaskAsync", [args, throwException], result.err);
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
catch (err) {
|
|
131
|
-
logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
|
|
132
|
-
if (throwException) {
|
|
133
|
-
throw err;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
97
|
+
return await this.executeFunction(() => this.actor.claimTask(args), "Network error: claim task failed", "claimTaskAsync", [args, throwException], null, throwException);
|
|
139
98
|
}
|
|
140
|
-
/**
|
|
141
|
-
* Completes a previously claimed task.
|
|
142
|
-
*/
|
|
143
99
|
async completeTaskAsync(args, throwException) {
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(() => this.actor.completeTask(args));
|
|
147
|
-
if ('ok' in result) {
|
|
148
|
-
return result.ok;
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
this.handleResultErrors("completeTaskAsync", [args, throwException], result.err);
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
catch (err) {
|
|
156
|
-
logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
|
|
157
|
-
if (throwException) {
|
|
158
|
-
throw err;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
100
|
+
return await this.executeFunction(() => this.actor.completeTask(args), "Network error: complete task failed", "completeTaskAsync", [args, throwException], false, throwException);
|
|
164
101
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Fetches IDs of tasks available in a specific channel.
|
|
167
|
-
*/
|
|
168
102
|
async getAvailableTaskIdsAsync(channel, throwException) {
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
const result = await this.runFunctionAndSyncTimeIfNecessaryAsyncUnsafe(() => this.actor.getAvailableTaskIds(channel));
|
|
172
|
-
if ('ok' in result) {
|
|
173
|
-
return result.ok;
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
this.handleResultErrors("getAvailableTaskIdsAsync", [channel, throwException], result.err);
|
|
177
|
-
return [];
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
catch (err) {
|
|
181
|
-
console.log("catch getAvailableTaskIdsAsync catch");
|
|
182
|
-
logErrorLocallyAndPublishOnErrorSubject(errorMessage, err);
|
|
183
|
-
if (throwException) {
|
|
184
|
-
throw err;
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
return [];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
103
|
+
return await this.executeFunction(() => this.actor.getAvailableTaskIds(channel), "Network error: get available task IDs failed", "getAvailableTaskIdsAsync", [channel, throwException], [], throwException);
|
|
190
104
|
}
|
|
191
105
|
}
|
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.18",
|
|
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.6.
|
|
30
|
+
"@jsm-mit/pigeon-package": "^0.6.2",
|
|
31
31
|
"@jsm-mit/utils-package": "^0.2.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|