crnd 0.0.1 → 0.0.4
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/bin/crnd +88 -0
- package/package.json +19 -43
- package/drizzle/0000_init.sql +0 -35
- package/drizzle/0001_add_runs.sql +0 -13
- package/drizzle/meta/_journal.json +0 -20
- package/src/cli/commands/createDeleteCommand.ts +0 -93
- package/src/cli/commands/createDoctorCommand.ts +0 -93
- package/src/cli/commands/createExportCommand.ts +0 -75
- package/src/cli/commands/createImportCommand.ts +0 -80
- package/src/cli/commands/createKillCommand.ts +0 -89
- package/src/cli/commands/createListCommand.ts +0 -67
- package/src/cli/commands/createLogsCommand.ts +0 -125
- package/src/cli/commands/createPauseCommand.ts +0 -78
- package/src/cli/commands/createResetCommand.ts +0 -78
- package/src/cli/commands/createResumeCommand.ts +0 -78
- package/src/cli/commands/createRootCommand.ts +0 -50
- package/src/cli/commands/createRunOnceCommand.ts +0 -77
- package/src/cli/commands/createRunsCommand.ts +0 -106
- package/src/cli/commands/createScheduleCommand.ts +0 -184
- package/src/cli/commands/createShowCommand.ts +0 -92
- package/src/cli/commands/createStatusCommand.ts +0 -145
- package/src/cli/commands/createStopCommand.ts +0 -89
- package/src/cli/commands/createUpdateCommand.ts +0 -13
- package/src/cli/commands/daemon/createDaemonCommand.ts +0 -24
- package/src/cli/commands/daemon/createDaemonInstallCommand.ts +0 -144
- package/src/cli/commands/daemon/createDaemonServeCommand.ts +0 -14
- package/src/cli/commands/daemon/createDaemonStartCommand.ts +0 -73
- package/src/cli/commands/daemon/createDaemonStatusCommand.ts +0 -5
- package/src/cli/commands/daemon/createDaemonStopCommand.ts +0 -59
- package/src/cli/commands/daemon/createDaemonUninstallCommand.ts +0 -99
- package/src/cli/commands/daemon/createLaunchdPlist.ts +0 -34
- package/src/cli/commands/daemon/createSystemdService.ts +0 -24
- package/src/cli/commands/daemon/escapeXml.ts +0 -8
- package/src/cli/commands/daemon/getDaemonServiceArgs.ts +0 -10
- package/src/cli/commands/daemon/quoteWindowsArg.ts +0 -4
- package/src/cli/commands/getCommandArgs.ts +0 -8
- package/src/cli/commands/parseEnvArgs.ts +0 -28
- package/src/cli/getDaemonSpawnArgs.ts +0 -9
- package/src/cli/main.ts +0 -8
- package/src/daemon/autostart/ensureAutostart.ts +0 -30
- package/src/daemon/autostart/getAutostartPath.ts +0 -29
- package/src/daemon/autostart/getDaemonInstallArgs.ts +0 -10
- package/src/daemon/createLogger.ts +0 -13
- package/src/daemon/createShutdownHandler.ts +0 -29
- package/src/daemon/jobs/createJobsFileSync.ts +0 -113
- package/src/daemon/jobs/deleteJobByName.ts +0 -18
- package/src/daemon/jobs/upsertJob.ts +0 -85
- package/src/daemon/main.ts +0 -64
- package/src/daemon/runner/createRunOutputFds.ts +0 -18
- package/src/daemon/runner/getRunStatus.ts +0 -14
- package/src/daemon/runner/recordSkippedRun.ts +0 -27
- package/src/daemon/runner/recoverRunningRuns.ts +0 -36
- package/src/daemon/runner/runJob.ts +0 -94
- package/src/daemon/scheduler/createScheduler.ts +0 -45
- package/src/daemon/scheduler/createSchedulerState.ts +0 -8
- package/src/daemon/scheduler/loadJobs.ts +0 -10
- package/src/daemon/scheduler/runJobWithTracking.ts +0 -48
- package/src/daemon/scheduler/scheduleJob.ts +0 -32
- package/src/daemon/scheduler/unscheduleJob.ts +0 -11
- package/src/daemon/scheduler/updateNextRunAt.ts +0 -14
- package/src/daemon/server/createApp.ts +0 -76
- package/src/daemon/server/createAuthMiddleware.ts +0 -16
- package/src/daemon/server/routes/registerExportRoute.ts +0 -21
- package/src/daemon/server/routes/registerHealthRoute.ts +0 -16
- package/src/daemon/server/routes/registerImportRoute.ts +0 -22
- package/src/daemon/server/routes/registerJobRunsRoute.ts +0 -46
- package/src/daemon/server/routes/registerJobsDeleteRoute.ts +0 -37
- package/src/daemon/server/routes/registerJobsGetRoute.ts +0 -29
- package/src/daemon/server/routes/registerJobsKillRoute.ts +0 -45
- package/src/daemon/server/routes/registerJobsListRoute.ts +0 -13
- package/src/daemon/server/routes/registerJobsPauseRoute.ts +0 -53
- package/src/daemon/server/routes/registerJobsResetRoute.ts +0 -54
- package/src/daemon/server/routes/registerJobsResumeRoute.ts +0 -53
- package/src/daemon/server/routes/registerJobsRunRoute.ts +0 -37
- package/src/daemon/server/routes/registerJobsStopRoute.ts +0 -45
- package/src/daemon/server/routes/registerJobsUpsertRoute.ts +0 -30
- package/src/daemon/server/routes/registerRunGetRoute.ts +0 -25
- package/src/daemon/server/routes/registerRunLogsRoute.ts +0 -32
- package/src/daemon/server/routes/registerShutdownRoute.ts +0 -9
- package/src/daemon/server/startServer.ts +0 -23
- package/src/db/getMigrationsDir.ts +0 -5
- package/src/db/migrateDatabase.ts +0 -21
- package/src/db/openDatabase.ts +0 -12
- package/src/db/schema/jobs.ts +0 -26
- package/src/db/schema/jobsSchemas.ts +0 -10
- package/src/db/schema/runs.ts +0 -23
- package/src/db/schema/runsSchemas.ts +0 -10
- package/src/db/schema.ts +0 -5
- package/src/shared/auth/createToken.ts +0 -5
- package/src/shared/events/appendEvent.ts +0 -16
- package/src/shared/jobs/createCommandSchema.ts +0 -5
- package/src/shared/jobs/createEnvSchema.ts +0 -5
- package/src/shared/jobs/createJobInputSchema.ts +0 -31
- package/src/shared/jobs/createTomlJobSchema.ts +0 -31
- package/src/shared/jobs/formatJobRow.ts +0 -14
- package/src/shared/jobs/isOverlapPolicy.ts +0 -5
- package/src/shared/jobs/parseCommand.ts +0 -6
- package/src/shared/jobs/parseEnv.ts +0 -10
- package/src/shared/jobs/parseJobsToml.ts +0 -36
- package/src/shared/jobs/readJobsToml.ts +0 -17
- package/src/shared/jobs/serializeCommand.ts +0 -6
- package/src/shared/jobs/serializeEnv.ts +0 -6
- package/src/shared/jobs/serializeJobsToml.ts +0 -45
- package/src/shared/jobs/writeJobsToml.ts +0 -12
- package/src/shared/paths/ensureDir.ts +0 -6
- package/src/shared/paths/getConfigDir.ts +0 -6
- package/src/shared/paths/getEventsPath.ts +0 -6
- package/src/shared/paths/getJobRunsDir.ts +0 -7
- package/src/shared/paths/getJobsTomlPath.ts +0 -6
- package/src/shared/paths/getPaths.ts +0 -16
- package/src/shared/paths/getRunOutputPaths.ts +0 -10
- package/src/shared/paths/getRunsDir.ts +0 -7
- package/src/shared/paths/getStateDir.ts +0 -8
- package/src/shared/rpc/createRpcClient.ts +0 -20
- package/src/shared/runs/formatRunRow.ts +0 -6
- package/src/shared/state/daemonStateSchema.ts +0 -13
- package/src/shared/state/getDaemonStatePath.ts +0 -6
- package/src/shared/state/readDaemonState.ts +0 -14
- package/src/shared/state/removeDaemonState.ts +0 -9
- package/src/shared/state/writeDaemonState.ts +0 -8
- package/src/shared/utils/isRecord.ts +0 -5
- package/src/shared/version.ts +0 -5
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from "citty";
|
|
2
|
-
import createRpcClient from "../../shared/rpc/createRpcClient";
|
|
3
|
-
|
|
4
|
-
export default function createListCommand() {
|
|
5
|
-
return defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: "list",
|
|
8
|
-
description: "List scheduled jobs",
|
|
9
|
-
},
|
|
10
|
-
args: {
|
|
11
|
-
json: {
|
|
12
|
-
type: "boolean",
|
|
13
|
-
alias: "j",
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
async run({ args }) {
|
|
17
|
-
const client = createRpcClient();
|
|
18
|
-
if (!client) {
|
|
19
|
-
const payload = { status: "unreachable" };
|
|
20
|
-
if (!process.stdout.isTTY || args.json) {
|
|
21
|
-
console.log(JSON.stringify(payload));
|
|
22
|
-
} else {
|
|
23
|
-
console.log("daemon: unreachable");
|
|
24
|
-
}
|
|
25
|
-
process.exitCode = 3;
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const res = await client.jobs.$get();
|
|
31
|
-
if (!res.ok) {
|
|
32
|
-
const payload = { status: "error", code: res.status };
|
|
33
|
-
if (!process.stdout.isTTY || args.json) {
|
|
34
|
-
console.log(JSON.stringify(payload));
|
|
35
|
-
} else {
|
|
36
|
-
console.log(`jobs: error (${res.status})`);
|
|
37
|
-
}
|
|
38
|
-
process.exitCode = 1;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const data = await res.json();
|
|
43
|
-
if (!process.stdout.isTTY || args.json) {
|
|
44
|
-
console.log(JSON.stringify(data));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (data.length === 0) {
|
|
49
|
-
console.log("jobs: none");
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
for (const job of data) {
|
|
54
|
-
console.log(`${job.name} (${job.id})`);
|
|
55
|
-
}
|
|
56
|
-
} catch {
|
|
57
|
-
const payload = { status: "unreachable" };
|
|
58
|
-
if (!process.stdout.isTTY || args.json) {
|
|
59
|
-
console.log(JSON.stringify(payload));
|
|
60
|
-
} else {
|
|
61
|
-
console.log("daemon: unreachable");
|
|
62
|
-
}
|
|
63
|
-
process.exitCode = 3;
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { defineCommand } from "citty";
|
|
3
|
-
import createRpcClient from "../../shared/rpc/createRpcClient";
|
|
4
|
-
|
|
5
|
-
export default function createLogsCommand() {
|
|
6
|
-
return defineCommand({
|
|
7
|
-
meta: {
|
|
8
|
-
name: "logs",
|
|
9
|
-
description: "Show latest run logs for a job",
|
|
10
|
-
},
|
|
11
|
-
args: {
|
|
12
|
-
name: {
|
|
13
|
-
type: "string",
|
|
14
|
-
alias: "n",
|
|
15
|
-
required: true,
|
|
16
|
-
},
|
|
17
|
-
show: {
|
|
18
|
-
type: "boolean",
|
|
19
|
-
alias: "s",
|
|
20
|
-
},
|
|
21
|
-
json: {
|
|
22
|
-
type: "boolean",
|
|
23
|
-
alias: "j",
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
async run({ args }) {
|
|
27
|
-
const client = createRpcClient();
|
|
28
|
-
if (!client) {
|
|
29
|
-
const payload = { status: "unreachable" };
|
|
30
|
-
if (!process.stdout.isTTY || args.json) {
|
|
31
|
-
console.log(JSON.stringify(payload));
|
|
32
|
-
} else {
|
|
33
|
-
console.log("daemon: unreachable");
|
|
34
|
-
}
|
|
35
|
-
process.exitCode = 3;
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
const res = await client.jobs[":name"].runs.$get({
|
|
41
|
-
param: { name: args.name },
|
|
42
|
-
query: { limit: "1" },
|
|
43
|
-
});
|
|
44
|
-
if (res.status === 404) {
|
|
45
|
-
const payload = { status: "not_found" };
|
|
46
|
-
if (!process.stdout.isTTY || args.json) {
|
|
47
|
-
console.log(JSON.stringify(payload));
|
|
48
|
-
} else {
|
|
49
|
-
console.log("logs: job not found");
|
|
50
|
-
}
|
|
51
|
-
process.exitCode = 1;
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!res.ok) {
|
|
56
|
-
const payload = { status: "error", code: res.status };
|
|
57
|
-
if (!process.stdout.isTTY || args.json) {
|
|
58
|
-
console.log(JSON.stringify(payload));
|
|
59
|
-
} else {
|
|
60
|
-
console.log(`logs: error (${res.status})`);
|
|
61
|
-
}
|
|
62
|
-
process.exitCode = 1;
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const data = await res.json();
|
|
67
|
-
if (!Array.isArray(data) || data.length === 0) {
|
|
68
|
-
const payload = { status: "no_runs" };
|
|
69
|
-
if (!process.stdout.isTTY || args.json) {
|
|
70
|
-
console.log(JSON.stringify(payload));
|
|
71
|
-
} else {
|
|
72
|
-
console.log("logs: no runs");
|
|
73
|
-
}
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const run = data[0];
|
|
78
|
-
if (!process.stdout.isTTY || args.json) {
|
|
79
|
-
console.log(JSON.stringify(run));
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!run.stdoutPath && !run.stderrPath) {
|
|
84
|
-
console.log("logs: no output paths");
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!args.show) {
|
|
89
|
-
if (run.stdoutPath) {
|
|
90
|
-
console.log(`stdout: ${run.stdoutPath}`);
|
|
91
|
-
}
|
|
92
|
-
if (run.stderrPath) {
|
|
93
|
-
console.log(`stderr: ${run.stderrPath}`);
|
|
94
|
-
}
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (run.stdoutPath) {
|
|
99
|
-
try {
|
|
100
|
-
console.log("-- stdout --");
|
|
101
|
-
console.log(readFileSync(run.stdoutPath, "utf-8"));
|
|
102
|
-
} catch {
|
|
103
|
-
console.log("logs: stdout missing");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (run.stderrPath) {
|
|
107
|
-
try {
|
|
108
|
-
console.log("-- stderr --");
|
|
109
|
-
console.log(readFileSync(run.stderrPath, "utf-8"));
|
|
110
|
-
} catch {
|
|
111
|
-
console.log("logs: stderr missing");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
} catch {
|
|
115
|
-
const payload = { status: "unreachable" };
|
|
116
|
-
if (!process.stdout.isTTY || args.json) {
|
|
117
|
-
console.log(JSON.stringify(payload));
|
|
118
|
-
} else {
|
|
119
|
-
console.log("daemon: unreachable");
|
|
120
|
-
}
|
|
121
|
-
process.exitCode = 3;
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from "citty";
|
|
2
|
-
import createRpcClient from "../../shared/rpc/createRpcClient";
|
|
3
|
-
|
|
4
|
-
export default function createPauseCommand() {
|
|
5
|
-
return defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: "pause",
|
|
8
|
-
description: "Pause a job",
|
|
9
|
-
},
|
|
10
|
-
args: {
|
|
11
|
-
name: {
|
|
12
|
-
type: "string",
|
|
13
|
-
alias: "n",
|
|
14
|
-
required: true,
|
|
15
|
-
},
|
|
16
|
-
json: {
|
|
17
|
-
type: "boolean",
|
|
18
|
-
alias: "j",
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
async run({ args }) {
|
|
22
|
-
const client = createRpcClient();
|
|
23
|
-
if (!client) {
|
|
24
|
-
const payload = { status: "unreachable" };
|
|
25
|
-
if (!process.stdout.isTTY || args.json) {
|
|
26
|
-
console.log(JSON.stringify(payload));
|
|
27
|
-
} else {
|
|
28
|
-
console.log("daemon: unreachable");
|
|
29
|
-
}
|
|
30
|
-
process.exitCode = 3;
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const res = await client.jobs[":name"].pause.$post({
|
|
36
|
-
param: { name: args.name },
|
|
37
|
-
});
|
|
38
|
-
if (res.status === 404) {
|
|
39
|
-
const payload = { status: "not_found" };
|
|
40
|
-
if (!process.stdout.isTTY || args.json) {
|
|
41
|
-
console.log(JSON.stringify(payload));
|
|
42
|
-
} else {
|
|
43
|
-
console.log("pause: job not found");
|
|
44
|
-
}
|
|
45
|
-
process.exitCode = 1;
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!res.ok) {
|
|
50
|
-
const payload = { status: "error", code: res.status };
|
|
51
|
-
if (!process.stdout.isTTY || args.json) {
|
|
52
|
-
console.log(JSON.stringify(payload));
|
|
53
|
-
} else {
|
|
54
|
-
console.log(`pause: error (${res.status})`);
|
|
55
|
-
}
|
|
56
|
-
process.exitCode = 1;
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const data = await res.json();
|
|
61
|
-
if (!process.stdout.isTTY || args.json) {
|
|
62
|
-
console.log(JSON.stringify(data));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log(`pause: ${data.name}`);
|
|
67
|
-
} catch {
|
|
68
|
-
const payload = { status: "unreachable" };
|
|
69
|
-
if (!process.stdout.isTTY || args.json) {
|
|
70
|
-
console.log(JSON.stringify(payload));
|
|
71
|
-
} else {
|
|
72
|
-
console.log("daemon: unreachable");
|
|
73
|
-
}
|
|
74
|
-
process.exitCode = 3;
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from "citty";
|
|
2
|
-
import createRpcClient from "../../shared/rpc/createRpcClient";
|
|
3
|
-
|
|
4
|
-
export default function createResetCommand() {
|
|
5
|
-
return defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: "reset",
|
|
8
|
-
description: "Reset job runs and scheduling state",
|
|
9
|
-
},
|
|
10
|
-
args: {
|
|
11
|
-
name: {
|
|
12
|
-
type: "string",
|
|
13
|
-
alias: "n",
|
|
14
|
-
required: true,
|
|
15
|
-
},
|
|
16
|
-
json: {
|
|
17
|
-
type: "boolean",
|
|
18
|
-
alias: "j",
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
async run({ args }) {
|
|
22
|
-
const client = createRpcClient();
|
|
23
|
-
if (!client) {
|
|
24
|
-
const payload = { status: "unreachable" };
|
|
25
|
-
if (!process.stdout.isTTY || args.json) {
|
|
26
|
-
console.log(JSON.stringify(payload));
|
|
27
|
-
} else {
|
|
28
|
-
console.log("daemon: unreachable");
|
|
29
|
-
}
|
|
30
|
-
process.exitCode = 3;
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const res = await client.jobs[":name"].reset.$post({
|
|
36
|
-
param: { name: args.name },
|
|
37
|
-
});
|
|
38
|
-
if (res.status === 404) {
|
|
39
|
-
const payload = { status: "not_found" };
|
|
40
|
-
if (!process.stdout.isTTY || args.json) {
|
|
41
|
-
console.log(JSON.stringify(payload));
|
|
42
|
-
} else {
|
|
43
|
-
console.log("reset: job not found");
|
|
44
|
-
}
|
|
45
|
-
process.exitCode = 1;
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!res.ok) {
|
|
50
|
-
const payload = { status: "error", code: res.status };
|
|
51
|
-
if (!process.stdout.isTTY || args.json) {
|
|
52
|
-
console.log(JSON.stringify(payload));
|
|
53
|
-
} else {
|
|
54
|
-
console.log(`reset: error (${res.status})`);
|
|
55
|
-
}
|
|
56
|
-
process.exitCode = 1;
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const data = await res.json();
|
|
61
|
-
if (!process.stdout.isTTY || args.json) {
|
|
62
|
-
console.log(JSON.stringify(data));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log(`reset: ${data.name}`);
|
|
67
|
-
} catch {
|
|
68
|
-
const payload = { status: "unreachable" };
|
|
69
|
-
if (!process.stdout.isTTY || args.json) {
|
|
70
|
-
console.log(JSON.stringify(payload));
|
|
71
|
-
} else {
|
|
72
|
-
console.log("daemon: unreachable");
|
|
73
|
-
}
|
|
74
|
-
process.exitCode = 3;
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from "citty";
|
|
2
|
-
import createRpcClient from "../../shared/rpc/createRpcClient";
|
|
3
|
-
|
|
4
|
-
export default function createResumeCommand() {
|
|
5
|
-
return defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: "resume",
|
|
8
|
-
description: "Resume a job",
|
|
9
|
-
},
|
|
10
|
-
args: {
|
|
11
|
-
name: {
|
|
12
|
-
type: "string",
|
|
13
|
-
alias: "n",
|
|
14
|
-
required: true,
|
|
15
|
-
},
|
|
16
|
-
json: {
|
|
17
|
-
type: "boolean",
|
|
18
|
-
alias: "j",
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
async run({ args }) {
|
|
22
|
-
const client = createRpcClient();
|
|
23
|
-
if (!client) {
|
|
24
|
-
const payload = { status: "unreachable" };
|
|
25
|
-
if (!process.stdout.isTTY || args.json) {
|
|
26
|
-
console.log(JSON.stringify(payload));
|
|
27
|
-
} else {
|
|
28
|
-
console.log("daemon: unreachable");
|
|
29
|
-
}
|
|
30
|
-
process.exitCode = 3;
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const res = await client.jobs[":name"].resume.$post({
|
|
36
|
-
param: { name: args.name },
|
|
37
|
-
});
|
|
38
|
-
if (res.status === 404) {
|
|
39
|
-
const payload = { status: "not_found" };
|
|
40
|
-
if (!process.stdout.isTTY || args.json) {
|
|
41
|
-
console.log(JSON.stringify(payload));
|
|
42
|
-
} else {
|
|
43
|
-
console.log("resume: job not found");
|
|
44
|
-
}
|
|
45
|
-
process.exitCode = 1;
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!res.ok) {
|
|
50
|
-
const payload = { status: "error", code: res.status };
|
|
51
|
-
if (!process.stdout.isTTY || args.json) {
|
|
52
|
-
console.log(JSON.stringify(payload));
|
|
53
|
-
} else {
|
|
54
|
-
console.log(`resume: error (${res.status})`);
|
|
55
|
-
}
|
|
56
|
-
process.exitCode = 1;
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const data = await res.json();
|
|
61
|
-
if (!process.stdout.isTTY || args.json) {
|
|
62
|
-
console.log(JSON.stringify(data));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log(`resume: ${data.name}`);
|
|
67
|
-
} catch {
|
|
68
|
-
const payload = { status: "unreachable" };
|
|
69
|
-
if (!process.stdout.isTTY || args.json) {
|
|
70
|
-
console.log(JSON.stringify(payload));
|
|
71
|
-
} else {
|
|
72
|
-
console.log("daemon: unreachable");
|
|
73
|
-
}
|
|
74
|
-
process.exitCode = 3;
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from "citty";
|
|
2
|
-
import getVersion from "../../shared/version";
|
|
3
|
-
import createDeleteCommand from "./createDeleteCommand";
|
|
4
|
-
import createDoctorCommand from "./createDoctorCommand";
|
|
5
|
-
import createExportCommand from "./createExportCommand";
|
|
6
|
-
import createImportCommand from "./createImportCommand";
|
|
7
|
-
import createKillCommand from "./createKillCommand";
|
|
8
|
-
import createListCommand from "./createListCommand";
|
|
9
|
-
import createLogsCommand from "./createLogsCommand";
|
|
10
|
-
import createPauseCommand from "./createPauseCommand";
|
|
11
|
-
import createResetCommand from "./createResetCommand";
|
|
12
|
-
import createResumeCommand from "./createResumeCommand";
|
|
13
|
-
import createRunOnceCommand from "./createRunOnceCommand";
|
|
14
|
-
import createRunsCommand from "./createRunsCommand";
|
|
15
|
-
import createScheduleCommand from "./createScheduleCommand";
|
|
16
|
-
import createShowCommand from "./createShowCommand";
|
|
17
|
-
import createStatusCommand from "./createStatusCommand";
|
|
18
|
-
import createStopCommand from "./createStopCommand";
|
|
19
|
-
import createUpdateCommand from "./createUpdateCommand";
|
|
20
|
-
import createDaemonCommand from "./daemon/createDaemonCommand";
|
|
21
|
-
|
|
22
|
-
export default function createRootCommand() {
|
|
23
|
-
return defineCommand({
|
|
24
|
-
meta: {
|
|
25
|
-
name: "crnd",
|
|
26
|
-
version: getVersion(),
|
|
27
|
-
description: "Local cron and scheduler",
|
|
28
|
-
},
|
|
29
|
-
subCommands: {
|
|
30
|
-
schedule: createScheduleCommand(),
|
|
31
|
-
update: createUpdateCommand(),
|
|
32
|
-
list: createListCommand(),
|
|
33
|
-
show: createShowCommand(),
|
|
34
|
-
runs: createRunsCommand(),
|
|
35
|
-
logs: createLogsCommand(),
|
|
36
|
-
delete: createDeleteCommand(),
|
|
37
|
-
pause: createPauseCommand(),
|
|
38
|
-
resume: createResumeCommand(),
|
|
39
|
-
reset: createResetCommand(),
|
|
40
|
-
stop: createStopCommand(),
|
|
41
|
-
kill: createKillCommand(),
|
|
42
|
-
export: createExportCommand(),
|
|
43
|
-
import: createImportCommand(),
|
|
44
|
-
doctor: createDoctorCommand(),
|
|
45
|
-
"run-once": createRunOnceCommand(),
|
|
46
|
-
status: createStatusCommand(),
|
|
47
|
-
daemon: createDaemonCommand(),
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from "citty";
|
|
2
|
-
import createRpcClient from "../../shared/rpc/createRpcClient";
|
|
3
|
-
|
|
4
|
-
export default function createRunOnceCommand() {
|
|
5
|
-
return defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: "run-once",
|
|
8
|
-
description: "Run a job immediately",
|
|
9
|
-
},
|
|
10
|
-
args: {
|
|
11
|
-
name: {
|
|
12
|
-
type: "string",
|
|
13
|
-
alias: "n",
|
|
14
|
-
required: true,
|
|
15
|
-
},
|
|
16
|
-
json: {
|
|
17
|
-
type: "boolean",
|
|
18
|
-
alias: "j",
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
async run({ args }) {
|
|
22
|
-
const client = createRpcClient();
|
|
23
|
-
if (!client) {
|
|
24
|
-
const payload = { status: "unreachable" };
|
|
25
|
-
if (!process.stdout.isTTY || args.json) {
|
|
26
|
-
console.log(JSON.stringify(payload));
|
|
27
|
-
} else {
|
|
28
|
-
console.log("daemon: unreachable");
|
|
29
|
-
}
|
|
30
|
-
process.exitCode = 3;
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const res = await client.jobs.run.$post({ json: { name: args.name } });
|
|
36
|
-
if (res.status === 404) {
|
|
37
|
-
const payload = { status: "not_found" };
|
|
38
|
-
if (!process.stdout.isTTY || args.json) {
|
|
39
|
-
console.log(JSON.stringify(payload));
|
|
40
|
-
} else {
|
|
41
|
-
console.log("run-once: job not found");
|
|
42
|
-
}
|
|
43
|
-
process.exitCode = 1;
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!res.ok) {
|
|
48
|
-
const payload = { status: "error", code: res.status };
|
|
49
|
-
if (!process.stdout.isTTY || args.json) {
|
|
50
|
-
console.log(JSON.stringify(payload));
|
|
51
|
-
} else {
|
|
52
|
-
console.log(`run-once: error (${res.status})`);
|
|
53
|
-
}
|
|
54
|
-
process.exitCode = 1;
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const data = await res.json();
|
|
59
|
-
if (!process.stdout.isTTY || args.json) {
|
|
60
|
-
console.log(JSON.stringify(data));
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const suffix = data.runId ? ` run ${data.runId}` : "";
|
|
65
|
-
console.log(`run-once: started (${data.jobId})${suffix}`);
|
|
66
|
-
} catch {
|
|
67
|
-
const payload = { status: "unreachable" };
|
|
68
|
-
if (!process.stdout.isTTY || args.json) {
|
|
69
|
-
console.log(JSON.stringify(payload));
|
|
70
|
-
} else {
|
|
71
|
-
console.log("daemon: unreachable");
|
|
72
|
-
}
|
|
73
|
-
process.exitCode = 3;
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from "citty";
|
|
2
|
-
import createRpcClient from "../../shared/rpc/createRpcClient";
|
|
3
|
-
|
|
4
|
-
export default function createRunsCommand() {
|
|
5
|
-
return defineCommand({
|
|
6
|
-
meta: {
|
|
7
|
-
name: "runs",
|
|
8
|
-
description: "List runs for a job",
|
|
9
|
-
},
|
|
10
|
-
args: {
|
|
11
|
-
name: {
|
|
12
|
-
type: "string",
|
|
13
|
-
alias: "n",
|
|
14
|
-
required: true,
|
|
15
|
-
},
|
|
16
|
-
limit: {
|
|
17
|
-
type: "string",
|
|
18
|
-
alias: "l",
|
|
19
|
-
},
|
|
20
|
-
json: {
|
|
21
|
-
type: "boolean",
|
|
22
|
-
alias: "j",
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
async run({ args }) {
|
|
26
|
-
const client = createRpcClient();
|
|
27
|
-
if (!client) {
|
|
28
|
-
const payload = { status: "unreachable" };
|
|
29
|
-
if (!process.stdout.isTTY || args.json) {
|
|
30
|
-
console.log(JSON.stringify(payload));
|
|
31
|
-
} else {
|
|
32
|
-
console.log("daemon: unreachable");
|
|
33
|
-
}
|
|
34
|
-
process.exitCode = 3;
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let limit: number | null = null;
|
|
39
|
-
if (args.limit) {
|
|
40
|
-
const parsed = Number(args.limit);
|
|
41
|
-
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
42
|
-
const payload = { status: "invalid_limit" };
|
|
43
|
-
if (!process.stdout.isTTY || args.json) {
|
|
44
|
-
console.log(JSON.stringify(payload));
|
|
45
|
-
} else {
|
|
46
|
-
console.log("runs: invalid limit");
|
|
47
|
-
}
|
|
48
|
-
process.exitCode = 2;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
limit = parsed;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const res = await client.jobs[":name"].runs.$get({
|
|
56
|
-
param: { name: args.name },
|
|
57
|
-
query: limit ? { limit: String(limit) } : {},
|
|
58
|
-
});
|
|
59
|
-
if (res.status === 404) {
|
|
60
|
-
const payload = { status: "not_found" };
|
|
61
|
-
if (!process.stdout.isTTY || args.json) {
|
|
62
|
-
console.log(JSON.stringify(payload));
|
|
63
|
-
} else {
|
|
64
|
-
console.log("runs: job not found");
|
|
65
|
-
}
|
|
66
|
-
process.exitCode = 1;
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!res.ok) {
|
|
71
|
-
const payload = { status: "error", code: res.status };
|
|
72
|
-
if (!process.stdout.isTTY || args.json) {
|
|
73
|
-
console.log(JSON.stringify(payload));
|
|
74
|
-
} else {
|
|
75
|
-
console.log(`runs: error (${res.status})`);
|
|
76
|
-
}
|
|
77
|
-
process.exitCode = 1;
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const data = await res.json();
|
|
82
|
-
if (!process.stdout.isTTY || args.json) {
|
|
83
|
-
console.log(JSON.stringify(data));
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (data.length === 0) {
|
|
88
|
-
console.log("runs: none");
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
for (const run of data) {
|
|
93
|
-
console.log(`${run.id} ${run.status} ${run.startedAt ?? ""}`.trim());
|
|
94
|
-
}
|
|
95
|
-
} catch {
|
|
96
|
-
const payload = { status: "unreachable" };
|
|
97
|
-
if (!process.stdout.isTTY || args.json) {
|
|
98
|
-
console.log(JSON.stringify(payload));
|
|
99
|
-
} else {
|
|
100
|
-
console.log("daemon: unreachable");
|
|
101
|
-
}
|
|
102
|
-
process.exitCode = 3;
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
}
|