@jsm-mit/rabbit-motoko-package 0.1.21 → 0.1.22
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.
|
@@ -9,27 +9,27 @@ export declare class RabbitMotokoActor {
|
|
|
9
9
|
private initActor;
|
|
10
10
|
private setupAgent;
|
|
11
11
|
private checkError;
|
|
12
|
-
|
|
12
|
+
syncTimeAsync(throwError: boolean): Promise<void>;
|
|
13
13
|
/**
|
|
14
14
|
* Adds a new task to the queue.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
addTaskAsync(args: AddTaskArgs, throwError: boolean): Promise<bigint>;
|
|
17
17
|
/**
|
|
18
18
|
* Claims a task for a specific worker.
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
claimTaskAsync(args: ClaimTaskArgs, throwError: boolean): Promise<[] | [Task]>;
|
|
21
21
|
/**
|
|
22
22
|
* Completes a previously claimed task.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
completeTaskAsync(args: CompleteTaskArgs, throwError: boolean): Promise<boolean>;
|
|
25
25
|
/**
|
|
26
26
|
* Fetches IDs of tasks available in a specific channel.
|
|
27
27
|
*/
|
|
28
|
-
|
|
28
|
+
getAvailableTaskIdsAsync(channel: string, throwError: boolean): Promise<bigint[]>;
|
|
29
29
|
/**
|
|
30
30
|
* Returns a list of all tasks.
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
getTasksAsync(throwError: boolean): Promise<Task[]>;
|
|
33
|
+
whoAmIAsync(throwError: boolean): Promise<string>;
|
|
34
34
|
}
|
|
35
35
|
//# 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":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,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EG;IACU,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAe9F;;OAEG;IACU,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAenD,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;CAgBjE"}
|
|
@@ -7,6 +7,7 @@ export class RabbitMotokoActor {
|
|
|
7
7
|
// 1. Tworzymy agenta
|
|
8
8
|
this.agent = HttpAgent.createSync({
|
|
9
9
|
host: this.host,
|
|
10
|
+
ingressExpiryInMinutes: 1,
|
|
10
11
|
identity,
|
|
11
12
|
});
|
|
12
13
|
// 2. Inicjalizujemy aktora
|
|
@@ -32,86 +33,114 @@ export class RabbitMotokoActor {
|
|
|
32
33
|
}
|
|
33
34
|
async checkError(error) {
|
|
34
35
|
const errorMsg = error?.toString() || "";
|
|
35
|
-
if (errorMsg.includes("certificate") || errorMsg.includes("TrustError")) {
|
|
36
|
+
if (errorMsg.includes("certificate") || errorMsg.includes("TrustError") || errorMsg.includes("ingress_expiry")) {
|
|
36
37
|
console.warn("⚠️ Wykryto problem z zaufaniem/czasem. Próbuję synchronizacji...");
|
|
37
|
-
await this.
|
|
38
|
+
await this.syncTimeAsync(false);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
async
|
|
41
|
+
async syncTimeAsync(throwError) {
|
|
41
42
|
try {
|
|
42
43
|
await this.agent.syncTime();
|
|
43
44
|
console.log("🔄 Czas agenta został zsynchronizowany ponownie.");
|
|
44
45
|
}
|
|
45
46
|
catch (err) {
|
|
46
47
|
console.error("❌ Nie udało się zsynchronizować czasu:", err);
|
|
48
|
+
if (throwError) {
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
/**
|
|
50
54
|
* Adds a new task to the queue.
|
|
51
55
|
*/
|
|
52
|
-
async
|
|
56
|
+
async addTaskAsync(args, throwError) {
|
|
53
57
|
try {
|
|
54
58
|
return await this.actor.addTask(args);
|
|
55
59
|
}
|
|
56
60
|
catch (error) {
|
|
57
61
|
await this.checkError(error);
|
|
58
62
|
console.error(`❌ Błąd podczas dodawania zadania:`, error);
|
|
59
|
-
|
|
63
|
+
if (throwError) {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return BigInt(0);
|
|
68
|
+
}
|
|
60
69
|
}
|
|
61
70
|
}
|
|
62
71
|
/**
|
|
63
72
|
* Claims a task for a specific worker.
|
|
64
73
|
*/
|
|
65
|
-
async
|
|
74
|
+
async claimTaskAsync(args, throwError) {
|
|
66
75
|
try {
|
|
67
76
|
return await this.actor.claimTask(args);
|
|
68
77
|
}
|
|
69
78
|
catch (error) {
|
|
70
79
|
await this.checkError(error);
|
|
71
80
|
console.error(`❌ Błąd podczas pobierania zadania (claimTask):`, error);
|
|
72
|
-
|
|
81
|
+
if (throwError) {
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
73
87
|
}
|
|
74
88
|
}
|
|
75
89
|
/**
|
|
76
90
|
* Completes a previously claimed task.
|
|
77
91
|
*/
|
|
78
|
-
async
|
|
92
|
+
async completeTaskAsync(args, throwError) {
|
|
79
93
|
try {
|
|
80
94
|
return await this.actor.completeTask(args);
|
|
81
95
|
}
|
|
82
96
|
catch (error) {
|
|
83
97
|
await this.checkError(error);
|
|
84
98
|
console.error(`❌ Błąd podczas zakończenia zadania:`, error);
|
|
85
|
-
|
|
99
|
+
if (throwError) {
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
86
105
|
}
|
|
87
106
|
}
|
|
88
107
|
/**
|
|
89
108
|
* Fetches IDs of tasks available in a specific channel.
|
|
90
109
|
*/
|
|
91
|
-
async
|
|
110
|
+
async getAvailableTaskIdsAsync(channel, throwError) {
|
|
92
111
|
try {
|
|
93
112
|
return await this.actor.getAvailableTaskIds(channel);
|
|
94
113
|
}
|
|
95
114
|
catch (error) {
|
|
96
115
|
await this.checkError(error);
|
|
97
116
|
console.error(`❌ Błąd podczas pobierania ID zadań (Kanał: ${channel}):`, error);
|
|
98
|
-
|
|
117
|
+
if (throwError) {
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
99
123
|
}
|
|
100
124
|
}
|
|
101
125
|
/**
|
|
102
126
|
* Returns a list of all tasks.
|
|
103
127
|
*/
|
|
104
|
-
async
|
|
128
|
+
async getTasksAsync(throwError) {
|
|
105
129
|
try {
|
|
106
130
|
return await this.actor.getTasks();
|
|
107
131
|
}
|
|
108
132
|
catch (error) {
|
|
109
133
|
await this.checkError(error);
|
|
110
134
|
console.error(`❌ Błąd podczas pobierania wszystkich zadań (getTasks):`, error);
|
|
111
|
-
|
|
135
|
+
if (throwError) {
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
112
141
|
}
|
|
113
142
|
}
|
|
114
|
-
async
|
|
143
|
+
async whoAmIAsync(throwError) {
|
|
115
144
|
try {
|
|
116
145
|
const x = await this.actor.whoAmI();
|
|
117
146
|
return x.toString();
|
|
@@ -119,7 +148,12 @@ export class RabbitMotokoActor {
|
|
|
119
148
|
catch (error) {
|
|
120
149
|
await this.checkError(error);
|
|
121
150
|
console.error(`❌ Błąd podczas pobierania informacji o użytkowniku (whoAmI):`, error);
|
|
122
|
-
|
|
151
|
+
if (throwError) {
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return "";
|
|
156
|
+
}
|
|
123
157
|
}
|
|
124
158
|
}
|
|
125
159
|
}
|