brainchain-worker 0.12.1 → 0.12.2
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/cli.js +4 -1
- package/dist/work.js +11 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ import { openStore, readWatched, writeWatched } from "./state.js";
|
|
|
14
14
|
import { createCreditChain, credit } from "./credit.js";
|
|
15
15
|
import { appeal, createDisputeChain, dispute } from "./dispute.js";
|
|
16
16
|
import { createReporter, createWatch, createWatchChain } from "./watch.js";
|
|
17
|
-
import { createWork, shellCommand, stopLeftover, stopper } from "./work.js";
|
|
17
|
+
import { createWork, firstProgram, programFound, shellCommand, stopLeftover, stopper } from "./work.js";
|
|
18
18
|
/** How many of the latest decisions a first watch --once checks. */
|
|
19
19
|
const FIRST_RUN_DECISIONS = 10n;
|
|
20
20
|
/** A published record's bytes as the service serves them, capped at a megabyte. */
|
|
@@ -310,6 +310,9 @@ async function run(network, { key, account }, values, once, mints) {
|
|
|
310
310
|
throw new UsageError("--timeout is the most minutes the command may spend on one task: more than 0, at most 1440, and 20 by default");
|
|
311
311
|
}
|
|
312
312
|
const log = (message) => console.log(`${new Date().toISOString().slice(0, 19)}Z ${message}`);
|
|
313
|
+
const program = firstProgram(exec);
|
|
314
|
+
if (program && !programFound(program))
|
|
315
|
+
log(`warning: the shell cannot find ${program}, so --exec will fail when the worker is hired`);
|
|
313
316
|
const store = openStore(account.address, network, log);
|
|
314
317
|
// The lock rules out a live run, so a command still in the state was left by one that died.
|
|
315
318
|
await stopLeftover(store, log);
|
package/dist/work.js
CHANGED
|
@@ -70,6 +70,15 @@ export function childEnv(extra) {
|
|
|
70
70
|
env[name] = value;
|
|
71
71
|
return { ...env, ...extra };
|
|
72
72
|
}
|
|
73
|
+
/** The program a shell command starts with, when it plainly starts with one; undefined for anything a shell has to interpret first. */
|
|
74
|
+
export function firstProgram(command) {
|
|
75
|
+
const word = /^\s*([^\s]+)/.exec(command)?.[1];
|
|
76
|
+
return word !== undefined && /^[\w./+-]+$/.test(word) ? word : undefined;
|
|
77
|
+
}
|
|
78
|
+
/** Whether the shell can find a program, for a warning at start; a typo otherwise only shows at the first hire. */
|
|
79
|
+
export function programFound(program) {
|
|
80
|
+
return spawnSync("sh", ["-c", 'command -v -- "$0" >/dev/null', program], { stdio: "ignore" }).status === 0;
|
|
81
|
+
}
|
|
73
82
|
function signalGroup(pid, signal) {
|
|
74
83
|
try {
|
|
75
84
|
process.kill(-pid, signal);
|
|
@@ -211,6 +220,8 @@ export function shellCommand(command, graceMs = 10_000) {
|
|
|
211
220
|
process.off("exit", kill);
|
|
212
221
|
if (stopped !== undefined)
|
|
213
222
|
return reject(new Error(stopped));
|
|
223
|
+
if (code === 126 || code === 127)
|
|
224
|
+
return reject(new Error(`The command exited with code ${code}: the shell could not ${code === 127 ? "find" : "run"} it`));
|
|
214
225
|
if (code !== 0)
|
|
215
226
|
return reject(new Error(signal ? `The command was stopped by ${signal}` : `The command exited with code ${code}`));
|
|
216
227
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainchain-worker",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Earn on BrainChain and propose changes to it: stake, apply, do the tasks Jev hires your agent for, and bond BRAIN to put a change to Jev.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BrainChain <hello@usebrainchain.com>",
|