@nosana/node 1.1.70 → 1.1.71-rc
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.
package/dist/package.json
CHANGED
|
@@ -12,6 +12,7 @@ export declare class JobHandler {
|
|
|
12
12
|
private id;
|
|
13
13
|
private job;
|
|
14
14
|
private runSubscriptionId;
|
|
15
|
+
private accountPollInterval;
|
|
15
16
|
private jobExternalUtil;
|
|
16
17
|
private eventEmitter;
|
|
17
18
|
private finishing;
|
|
@@ -37,6 +38,13 @@ export declare class JobHandler {
|
|
|
37
38
|
nodeStop(): Promise<void>;
|
|
38
39
|
validate(jobDefinition: JobDefinition): Promise<boolean>;
|
|
39
40
|
private listenForAccountChanges;
|
|
41
|
+
/**
|
|
42
|
+
* The subscription alone is not enough: a websocket can drop a
|
|
43
|
+
* notification. Reading the chain on an interval keeps the node from
|
|
44
|
+
* working a job that has already ended onchain.
|
|
45
|
+
*/
|
|
46
|
+
private pollForAccountChanges;
|
|
47
|
+
private stopPollingForAccountChanges;
|
|
40
48
|
private stopListeningForAccountChanges;
|
|
41
49
|
start(job: Job): Promise<boolean>;
|
|
42
50
|
runWithErrorHandling(): Promise<void>;
|
|
@@ -99,6 +99,9 @@ export class JobHandler {
|
|
|
99
99
|
await TaskManagerRegistry.getInstance().stop();
|
|
100
100
|
await JobRegistry.getInstance().stop(this.sdk, this.repository);
|
|
101
101
|
this.stopListeningForAccountChanges();
|
|
102
|
+
// every cycle registers its own listeners, the previous job's must not
|
|
103
|
+
// answer for the next one
|
|
104
|
+
this.accountEmitter.removeAllListeners();
|
|
102
105
|
this.clearJob();
|
|
103
106
|
}
|
|
104
107
|
async validate(jobDefinition) {
|
|
@@ -141,7 +144,41 @@ export class JobHandler {
|
|
|
141
144
|
}
|
|
142
145
|
});
|
|
143
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* The subscription alone is not enough: a websocket can drop a
|
|
149
|
+
* notification. Reading the chain on an interval keeps the node from
|
|
150
|
+
* working a job that has already ended onchain.
|
|
151
|
+
*/
|
|
152
|
+
pollForAccountChanges() {
|
|
153
|
+
const jobAddress = new PublicKey(this.jobId());
|
|
154
|
+
const interval = setInterval(async () => {
|
|
155
|
+
try {
|
|
156
|
+
const jobAccount = await this.sdk.jobs.jobs.account.jobAccount.fetch(jobAddress);
|
|
157
|
+
// stopped or replaced by the next job while the request was out
|
|
158
|
+
if (this.accountPollInterval !== interval)
|
|
159
|
+
return;
|
|
160
|
+
if (jobAccount.state >= 2) {
|
|
161
|
+
this.stopPollingForAccountChanges();
|
|
162
|
+
this.finishing = true;
|
|
163
|
+
this.accountEmitter.emit('stopped', jobAccount);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
this.accountEmitter.emit('changed', jobAccount);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// an RPC failure says nothing about the job, the next poll retries
|
|
170
|
+
}
|
|
171
|
+
}, 60000);
|
|
172
|
+
this.accountPollInterval = interval;
|
|
173
|
+
}
|
|
174
|
+
stopPollingForAccountChanges() {
|
|
175
|
+
if (this.accountPollInterval) {
|
|
176
|
+
clearInterval(this.accountPollInterval);
|
|
177
|
+
this.accountPollInterval = undefined;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
144
180
|
stopListeningForAccountChanges() {
|
|
181
|
+
this.stopPollingForAccountChanges();
|
|
145
182
|
if (this.runSubscriptionId !== undefined) {
|
|
146
183
|
this.sdk.jobs.connection.removeProgramAccountChangeListener(this.runSubscriptionId);
|
|
147
184
|
this.runSubscriptionId = undefined;
|
|
@@ -187,6 +224,7 @@ export class JobHandler {
|
|
|
187
224
|
}
|
|
188
225
|
}
|
|
189
226
|
this.listenForAccountChanges();
|
|
227
|
+
this.pollForAccountChanges();
|
|
190
228
|
return true;
|
|
191
229
|
}
|
|
192
230
|
async runWithErrorHandling() {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosana/node",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.71-rc",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@nosana/node",
|
|
9
|
-
"version": "1.1.
|
|
9
|
+
"version": "1.1.71-rc",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@coral-xyz/anchor": "^0.28.1-beta.1",
|