@somewhere-cloud/cli 0.38.156 → 0.38.158
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/CHANGELOG.md +8 -0
- package/dist/lib/bundle.js +64 -36
- package/dist/lib/bundle.js.map +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.38.158
|
|
4
|
+
|
|
5
|
+
- `somewhere cron run <name> --wait` reports job completion sooner.
|
|
6
|
+
|
|
7
|
+
## 0.38.157
|
|
8
|
+
|
|
9
|
+
- Generated starter guides show how to import large CSV files in background jobs using batched writes.
|
|
10
|
+
|
|
3
11
|
## 0.38.156
|
|
4
12
|
|
|
5
13
|
- Piping a docs topic or redirecting it to a file prints the full topic. Use `somewhere docs --search "<words>"` to find matching sections or `somewhere docs pull` to download current Markdown into your project.
|
package/dist/lib/bundle.js
CHANGED
|
@@ -42319,6 +42319,9 @@ var init_http = __esm({
|
|
|
42319
42319
|
function interactivePollDelay(attempt) {
|
|
42320
42320
|
return [150, 300, 600][attempt] ?? 1e3;
|
|
42321
42321
|
}
|
|
42322
|
+
function jobPollDelay(elapsedMs) {
|
|
42323
|
+
return elapsedMs < 8e3 ? 150 : 1e3;
|
|
42324
|
+
}
|
|
42322
42325
|
function retryAfterMs(value, now2 = Date.now()) {
|
|
42323
42326
|
const header = value?.trim();
|
|
42324
42327
|
if (!header)
|
|
@@ -42332,6 +42335,7 @@ var init_poll_delay = __esm({
|
|
|
42332
42335
|
"dist/lib/poll-delay.js"() {
|
|
42333
42336
|
"use strict";
|
|
42334
42337
|
__name(interactivePollDelay, "interactivePollDelay");
|
|
42338
|
+
__name(jobPollDelay, "jobPollDelay");
|
|
42335
42339
|
__name(retryAfterMs, "retryAfterMs");
|
|
42336
42340
|
}
|
|
42337
42341
|
});
|
|
@@ -44183,6 +44187,16 @@ Use \`somewhere docs <topic> --section <id>\` for one section or \`--full\` for
|
|
|
44183
44187
|
PREVIEW_POINTER = "Preview users are separate from live users. Sign up in the preview or use `somewhere preview user-add`. Check captured mail with `somewhere preview mail`.";
|
|
44184
44188
|
INIT_AGENTS_MD = `# somewhere.cloud project contract
|
|
44185
44189
|
${AGENT_WORKFLOW}
|
|
44190
|
+
### CSV imports
|
|
44191
|
+
|
|
44192
|
+
Use one background job for a large import. Normalize and deduplicate keys
|
|
44193
|
+
before writing. Pair schema uniqueness with an \`onConflict\` action that makes
|
|
44194
|
+
each batch safe to retry. Send up to 100 writes per transaction with \`sw.db.tx\` or \`sw.db.server.tx\`.
|
|
44195
|
+
Await dependent batches in order. Run up to four independent batches together,
|
|
44196
|
+
then write one progress update for the group. Set the job deadline from a timed
|
|
44197
|
+
import on your deployed app. See \`somewhere docs recipe-csv-import --full\`
|
|
44198
|
+
for the upload, job and ownership checks.
|
|
44199
|
+
|
|
44186
44200
|
${SKILLS_POINTER}
|
|
44187
44201
|
Search the live docs with \`somewhere docs --search "<words>"\`.
|
|
44188
44202
|
Download Markdown to \`.somewhere/docs/\` with \`somewhere docs pull\`.
|
|
@@ -89851,12 +89865,12 @@ async function folderPreviewTool(opts) {
|
|
|
89851
89865
|
async function previewCurrentVersion(credential) {
|
|
89852
89866
|
return previewToolClient(credential).call("GET", "/preview-tools/whoami");
|
|
89853
89867
|
}
|
|
89854
|
-
async function waitForPreviewJob(
|
|
89855
|
-
const
|
|
89856
|
-
const deadline =
|
|
89868
|
+
async function waitForPreviewJob(client, jobId, timeoutSeconds, firstDelayMs = 0) {
|
|
89869
|
+
const startedAt = Date.now();
|
|
89870
|
+
const deadline = startedAt + timeoutSeconds * 1e3;
|
|
89857
89871
|
let job;
|
|
89858
89872
|
let delay2 = firstDelayMs;
|
|
89859
|
-
for (
|
|
89873
|
+
for (; ; ) {
|
|
89860
89874
|
const remaining = deadline - Date.now();
|
|
89861
89875
|
if (delay2 >= remaining) {
|
|
89862
89876
|
if (remaining > 0)
|
|
@@ -89881,7 +89895,7 @@ async function waitForPreviewJob(credential, jobId, timeoutSeconds, firstDelayMs
|
|
|
89881
89895
|
throw error3;
|
|
89882
89896
|
retryAfter = Math.max(retryAfter, error3.meta.retryAfterMs);
|
|
89883
89897
|
}
|
|
89884
|
-
delay2 = Math.max(
|
|
89898
|
+
delay2 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter);
|
|
89885
89899
|
}
|
|
89886
89900
|
}
|
|
89887
89901
|
var TERMINAL;
|
|
@@ -90202,7 +90216,11 @@ To run a production schedule's handler and payload this way: ${cliInvocation()}
|
|
|
90202
90216
|
if (!Number.isFinite(timeout) || timeout < 1 || timeout > 3600)
|
|
90203
90217
|
throw new Error("--timeout must be a number of seconds from 1 to 3600. Nothing ran.");
|
|
90204
90218
|
target = await previewToolTarget(opts);
|
|
90205
|
-
const
|
|
90219
|
+
const client = previewToolClient(target.credential);
|
|
90220
|
+
let firstDelayMs = 0;
|
|
90221
|
+
const queued = await client.call("POST", "/preview-tools/run-job", { handler: handlerPath, ...payload !== void 0 ? { payload } : {} }, void 0, { onRetryAfter: /* @__PURE__ */ __name((ms2) => {
|
|
90222
|
+
firstDelayMs = ms2;
|
|
90223
|
+
}, "onRetryAfter") });
|
|
90206
90224
|
if (opts.wait === false) {
|
|
90207
90225
|
if (opts.json) {
|
|
90208
90226
|
printJson(queued);
|
|
@@ -90214,7 +90232,7 @@ To run a production schedule's handler and payload this way: ${cliInvocation()}
|
|
|
90214
90232
|
}
|
|
90215
90233
|
if (!opts.json)
|
|
90216
90234
|
console.log(dim(`Job ${queued.job_id} queued in preview ${queued.preview_session_id} (version ${queued.preview_id}); waiting up to ${timeout}s\u2026`));
|
|
90217
|
-
const { job, timedOut } = await waitForPreviewJob(
|
|
90235
|
+
const { job, timedOut } = await waitForPreviewJob(client, queued.job_id, timeout, firstDelayMs);
|
|
90218
90236
|
const succeeded = !timedOut && job.status === "complete";
|
|
90219
90237
|
if (!succeeded)
|
|
90220
90238
|
process.exitCode = 1;
|
|
@@ -133553,13 +133571,13 @@ function parseWaitTimeout(value) {
|
|
|
133553
133571
|
function isTerminalJobStatus(status) {
|
|
133554
133572
|
return status === JOB_SUCCESS_STATUS || JOB_FAILURE_STATUSES.has(status);
|
|
133555
133573
|
}
|
|
133556
|
-
async function waitForJob(admitted, timeoutSeconds, firstDelayMs) {
|
|
133557
|
-
const client = new ApiClient(getToken());
|
|
133574
|
+
async function waitForJob(client, admitted, timeoutSeconds, firstDelayMs) {
|
|
133558
133575
|
const path3 = "/jobs/" + encodeURIComponent(admitted.job_id);
|
|
133559
|
-
const
|
|
133576
|
+
const startedAt = Date.now();
|
|
133577
|
+
const deadline = startedAt + timeoutSeconds * 1e3;
|
|
133560
133578
|
let job = admitted;
|
|
133561
133579
|
let delay2 = firstDelayMs;
|
|
133562
|
-
for (
|
|
133580
|
+
for (; ; ) {
|
|
133563
133581
|
const remaining = deadline - Date.now();
|
|
133564
133582
|
if (delay2 >= remaining) {
|
|
133565
133583
|
if (remaining > 0)
|
|
@@ -133584,7 +133602,7 @@ async function waitForJob(admitted, timeoutSeconds, firstDelayMs) {
|
|
|
133584
133602
|
throw error3;
|
|
133585
133603
|
retryAfter = Math.max(retryAfter ?? 0, hint ?? 0);
|
|
133586
133604
|
}
|
|
133587
|
-
delay2 = Math.max(
|
|
133605
|
+
delay2 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter ?? 0);
|
|
133588
133606
|
}
|
|
133589
133607
|
}
|
|
133590
133608
|
function observedCronConfig(cron) {
|
|
@@ -133751,11 +133769,7 @@ function printTypedCronError(code, message3, json, extra) {
|
|
|
133751
133769
|
function cronProjectScope(explicit) {
|
|
133752
133770
|
return explicit ?? loadProjectConfig()?.project_id;
|
|
133753
133771
|
}
|
|
133754
|
-
|
|
133755
|
-
const project = cronProjectScope(explicit);
|
|
133756
|
-
const rows = cronRows(await callPlatformTool("cron_list", compactRecord([
|
|
133757
|
-
["project_id", project]
|
|
133758
|
-
]), { allTools: true, signal }));
|
|
133772
|
+
function matchNamedCron(target, project, rows) {
|
|
133759
133773
|
const matches = rows.filter((row) => row.name === target);
|
|
133760
133774
|
if (matches.length === 0) {
|
|
133761
133775
|
throw new Error(`CRON_NOT_FOUND: No scheduled task named "${target}" was found${project ? ` in project "${project}"` : ""}.`);
|
|
@@ -133768,6 +133782,20 @@ async function findNamedCronRow(target, explicit, signal) {
|
|
|
133768
133782
|
throw new Error("cron_list returned a scheduled task without a cron_id.");
|
|
133769
133783
|
return { ...matches[0], cron_id: id };
|
|
133770
133784
|
}
|
|
133785
|
+
async function findNamedCronRow(target, explicit, signal) {
|
|
133786
|
+
const project = cronProjectScope(explicit);
|
|
133787
|
+
const rows = cronRows(await callPlatformTool("cron_list", compactRecord([
|
|
133788
|
+
["project_id", project]
|
|
133789
|
+
]), { allTools: true, signal }));
|
|
133790
|
+
return matchNamedCron(target, project, rows);
|
|
133791
|
+
}
|
|
133792
|
+
async function resolveRunCronId(client, target, explicit) {
|
|
133793
|
+
if (target.startsWith("cron_"))
|
|
133794
|
+
return target;
|
|
133795
|
+
const project = cronProjectScope(explicit);
|
|
133796
|
+
const rows = cronRows(await client.call("GET", "/cron", void 0, { project_id: project }));
|
|
133797
|
+
return matchNamedCron(target, project, rows).cron_id;
|
|
133798
|
+
}
|
|
133771
133799
|
async function resolveCronId(target, explicit) {
|
|
133772
133800
|
if (target.startsWith("cron_"))
|
|
133773
133801
|
return target;
|
|
@@ -133834,20 +133862,18 @@ function printCronMutation(verb, value) {
|
|
|
133834
133862
|
const id = isRecord(data2) && typeof data2.id === "string" ? data2.id : isRecord(data2) && typeof data2.cron_id === "string" ? data2.cron_id : null;
|
|
133835
133863
|
success(`${verb}${id ? ` ${id}` : ""}.`);
|
|
133836
133864
|
}
|
|
133837
|
-
async function runCronInPreview(cronId, opts, timeoutSeconds) {
|
|
133865
|
+
async function runCronInPreview(client, cronId, opts, timeoutSeconds) {
|
|
133838
133866
|
const tool = await folderPreviewTool({});
|
|
133839
133867
|
const version2 = await previewCurrentVersion(tool.credential);
|
|
133840
133868
|
let firstDelayMs = 0;
|
|
133841
|
-
const
|
|
133842
|
-
allTools: true,
|
|
133869
|
+
const result = cronRunResult(await client.call("POST", `/cron/${encodeURIComponent(cronId)}/run-preview`, version2, void 0, {
|
|
133843
133870
|
onRetryAfter: /* @__PURE__ */ __name((ms2) => {
|
|
133844
|
-
firstDelayMs =
|
|
133871
|
+
firstDelayMs = ms2;
|
|
133845
133872
|
}, "onRetryAfter")
|
|
133846
|
-
});
|
|
133847
|
-
const result = cronRunResult(value);
|
|
133873
|
+
}));
|
|
133848
133874
|
if (!opts.wait) {
|
|
133849
133875
|
if (opts.json) {
|
|
133850
|
-
printJson(
|
|
133876
|
+
printJson({ ok: true, data: result });
|
|
133851
133877
|
return;
|
|
133852
133878
|
}
|
|
133853
133879
|
success(`Scheduled task queued in preview ${version2.preview_session_id} (not finished yet). Job ${result.job_id}.`);
|
|
@@ -133856,7 +133882,7 @@ async function runCronInPreview(cronId, opts, timeoutSeconds) {
|
|
|
133856
133882
|
}
|
|
133857
133883
|
if (!opts.json)
|
|
133858
133884
|
console.log(dim(`Job ${result.job_id} queued in preview ${version2.preview_session_id} for cron ${result.cron_id}; waiting up to ${timeoutSeconds}s\u2026`));
|
|
133859
|
-
const { job, timedOut } = await waitForPreviewJob(tool.credential, result.job_id, timeoutSeconds, firstDelayMs);
|
|
133885
|
+
const { job, timedOut } = await waitForPreviewJob(previewToolClient(tool.credential), result.job_id, timeoutSeconds, firstDelayMs);
|
|
133860
133886
|
const succeeded = !timedOut && job.status === JOB_SUCCESS_STATUS;
|
|
133861
133887
|
if (!succeeded)
|
|
133862
133888
|
process.exitCode = 1;
|
|
@@ -133931,38 +133957,37 @@ zone each trigger is stored in, and \`cron update --schedule\` keeps that zone u
|
|
|
133931
133957
|
if (opts.timeout !== void 0 && !opts.wait) {
|
|
133932
133958
|
throw new Error("USAGE_ERROR: --timeout only applies with --wait.");
|
|
133933
133959
|
}
|
|
133934
|
-
const
|
|
133960
|
+
const client = new ApiClient(getToken());
|
|
133961
|
+
const cronId = await resolveRunCronId(client, target, opts.project);
|
|
133935
133962
|
if (opts.preview) {
|
|
133936
133963
|
if (opts.twice) {
|
|
133937
133964
|
await printPreviewScheduleTest(cronId, await folderPreviewTool({}), true, Boolean(opts.json));
|
|
133938
133965
|
return;
|
|
133939
133966
|
}
|
|
133940
|
-
await runCronInPreview(cronId, opts, timeoutSeconds);
|
|
133967
|
+
await runCronInPreview(client, cronId, opts, timeoutSeconds);
|
|
133941
133968
|
return;
|
|
133942
133969
|
}
|
|
133943
133970
|
let firstDelayMs = 0;
|
|
133944
|
-
const value = await
|
|
133945
|
-
allTools: true,
|
|
133971
|
+
const value = await client.call("POST", `/cron/${encodeURIComponent(cronId)}/run`, void 0, void 0, {
|
|
133946
133972
|
onRetryAfter: /* @__PURE__ */ __name((ms2) => {
|
|
133947
|
-
firstDelayMs =
|
|
133973
|
+
firstDelayMs = ms2;
|
|
133948
133974
|
}, "onRetryAfter")
|
|
133949
133975
|
});
|
|
133950
133976
|
queued = true;
|
|
133977
|
+
const result = cronRunResult(value);
|
|
133951
133978
|
if (!opts.wait) {
|
|
133952
133979
|
if (opts.json) {
|
|
133953
|
-
printJson(
|
|
133980
|
+
printJson({ ok: true, data: result });
|
|
133954
133981
|
return;
|
|
133955
133982
|
}
|
|
133956
|
-
|
|
133957
|
-
|
|
133958
|
-
console.log(dim(`Cron ${result2.cron_id} Job ${result2.job_id} ${result2.status} trigger: ${result2.trigger}`));
|
|
133983
|
+
success(`Scheduled task queued (not finished yet). Job ${result.job_id}.`);
|
|
133984
|
+
console.log(dim(`Cron ${result.cron_id} Job ${result.job_id} ${result.status} trigger: ${result.trigger}`));
|
|
133959
133985
|
console.log(dim("Pass --wait to wait for the run to finish and see its result."));
|
|
133960
133986
|
return;
|
|
133961
133987
|
}
|
|
133962
|
-
const result = cronRunResult(value);
|
|
133963
133988
|
if (!opts.json)
|
|
133964
133989
|
console.log(dim(`Job ${result.job_id} queued for cron ${result.cron_id}; waiting up to ${timeoutSeconds}s\u2026`));
|
|
133965
|
-
const { job, timedOut } = await waitForJob(result, timeoutSeconds, firstDelayMs);
|
|
133990
|
+
const { job, timedOut } = await waitForJob(client, result, timeoutSeconds, firstDelayMs);
|
|
133966
133991
|
const succeeded = !timedOut && job.status === JOB_SUCCESS_STATUS;
|
|
133967
133992
|
if (!succeeded)
|
|
133968
133993
|
process.exitCode = 1;
|
|
@@ -134105,6 +134130,7 @@ var init_cron = __esm({
|
|
|
134105
134130
|
init_next_actions();
|
|
134106
134131
|
init_platform_tools();
|
|
134107
134132
|
init_poll_delay();
|
|
134133
|
+
init_preview_credential();
|
|
134108
134134
|
init_preview_jobs();
|
|
134109
134135
|
init_platform_command();
|
|
134110
134136
|
init_output();
|
|
@@ -134132,7 +134158,9 @@ var init_cron = __esm({
|
|
|
134132
134158
|
__name(cronRunUnavailable, "cronRunUnavailable");
|
|
134133
134159
|
__name(printTypedCronError, "printTypedCronError");
|
|
134134
134160
|
__name(cronProjectScope, "cronProjectScope");
|
|
134161
|
+
__name(matchNamedCron, "matchNamedCron");
|
|
134135
134162
|
__name(findNamedCronRow, "findNamedCronRow");
|
|
134163
|
+
__name(resolveRunCronId, "resolveRunCronId");
|
|
134136
134164
|
__name(resolveCronId, "resolveCronId");
|
|
134137
134165
|
__name(findCronRow, "findCronRow");
|
|
134138
134166
|
__name(nextRunLabel, "nextRunLabel");
|