@somewhere-cloud/cli 0.38.157 → 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 +4 -0
- package/dist/lib/bundle.js +54 -36
- package/dist/lib/bundle.js.map +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
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
|
});
|
|
@@ -89861,12 +89865,12 @@ async function folderPreviewTool(opts) {
|
|
|
89861
89865
|
async function previewCurrentVersion(credential) {
|
|
89862
89866
|
return previewToolClient(credential).call("GET", "/preview-tools/whoami");
|
|
89863
89867
|
}
|
|
89864
|
-
async function waitForPreviewJob(
|
|
89865
|
-
const
|
|
89866
|
-
const deadline =
|
|
89868
|
+
async function waitForPreviewJob(client, jobId, timeoutSeconds, firstDelayMs = 0) {
|
|
89869
|
+
const startedAt = Date.now();
|
|
89870
|
+
const deadline = startedAt + timeoutSeconds * 1e3;
|
|
89867
89871
|
let job;
|
|
89868
89872
|
let delay2 = firstDelayMs;
|
|
89869
|
-
for (
|
|
89873
|
+
for (; ; ) {
|
|
89870
89874
|
const remaining = deadline - Date.now();
|
|
89871
89875
|
if (delay2 >= remaining) {
|
|
89872
89876
|
if (remaining > 0)
|
|
@@ -89891,7 +89895,7 @@ async function waitForPreviewJob(credential, jobId, timeoutSeconds, firstDelayMs
|
|
|
89891
89895
|
throw error3;
|
|
89892
89896
|
retryAfter = Math.max(retryAfter, error3.meta.retryAfterMs);
|
|
89893
89897
|
}
|
|
89894
|
-
delay2 = Math.max(
|
|
89898
|
+
delay2 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter);
|
|
89895
89899
|
}
|
|
89896
89900
|
}
|
|
89897
89901
|
var TERMINAL;
|
|
@@ -90212,7 +90216,11 @@ To run a production schedule's handler and payload this way: ${cliInvocation()}
|
|
|
90212
90216
|
if (!Number.isFinite(timeout) || timeout < 1 || timeout > 3600)
|
|
90213
90217
|
throw new Error("--timeout must be a number of seconds from 1 to 3600. Nothing ran.");
|
|
90214
90218
|
target = await previewToolTarget(opts);
|
|
90215
|
-
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") });
|
|
90216
90224
|
if (opts.wait === false) {
|
|
90217
90225
|
if (opts.json) {
|
|
90218
90226
|
printJson(queued);
|
|
@@ -90224,7 +90232,7 @@ To run a production schedule's handler and payload this way: ${cliInvocation()}
|
|
|
90224
90232
|
}
|
|
90225
90233
|
if (!opts.json)
|
|
90226
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`));
|
|
90227
|
-
const { job, timedOut } = await waitForPreviewJob(
|
|
90235
|
+
const { job, timedOut } = await waitForPreviewJob(client, queued.job_id, timeout, firstDelayMs);
|
|
90228
90236
|
const succeeded = !timedOut && job.status === "complete";
|
|
90229
90237
|
if (!succeeded)
|
|
90230
90238
|
process.exitCode = 1;
|
|
@@ -133563,13 +133571,13 @@ function parseWaitTimeout(value) {
|
|
|
133563
133571
|
function isTerminalJobStatus(status) {
|
|
133564
133572
|
return status === JOB_SUCCESS_STATUS || JOB_FAILURE_STATUSES.has(status);
|
|
133565
133573
|
}
|
|
133566
|
-
async function waitForJob(admitted, timeoutSeconds, firstDelayMs) {
|
|
133567
|
-
const client = new ApiClient(getToken());
|
|
133574
|
+
async function waitForJob(client, admitted, timeoutSeconds, firstDelayMs) {
|
|
133568
133575
|
const path3 = "/jobs/" + encodeURIComponent(admitted.job_id);
|
|
133569
|
-
const
|
|
133576
|
+
const startedAt = Date.now();
|
|
133577
|
+
const deadline = startedAt + timeoutSeconds * 1e3;
|
|
133570
133578
|
let job = admitted;
|
|
133571
133579
|
let delay2 = firstDelayMs;
|
|
133572
|
-
for (
|
|
133580
|
+
for (; ; ) {
|
|
133573
133581
|
const remaining = deadline - Date.now();
|
|
133574
133582
|
if (delay2 >= remaining) {
|
|
133575
133583
|
if (remaining > 0)
|
|
@@ -133594,7 +133602,7 @@ async function waitForJob(admitted, timeoutSeconds, firstDelayMs) {
|
|
|
133594
133602
|
throw error3;
|
|
133595
133603
|
retryAfter = Math.max(retryAfter ?? 0, hint ?? 0);
|
|
133596
133604
|
}
|
|
133597
|
-
delay2 = Math.max(
|
|
133605
|
+
delay2 = Math.max(jobPollDelay(Date.now() - startedAt), retryAfter ?? 0);
|
|
133598
133606
|
}
|
|
133599
133607
|
}
|
|
133600
133608
|
function observedCronConfig(cron) {
|
|
@@ -133761,11 +133769,7 @@ function printTypedCronError(code, message3, json, extra) {
|
|
|
133761
133769
|
function cronProjectScope(explicit) {
|
|
133762
133770
|
return explicit ?? loadProjectConfig()?.project_id;
|
|
133763
133771
|
}
|
|
133764
|
-
|
|
133765
|
-
const project = cronProjectScope(explicit);
|
|
133766
|
-
const rows = cronRows(await callPlatformTool("cron_list", compactRecord([
|
|
133767
|
-
["project_id", project]
|
|
133768
|
-
]), { allTools: true, signal }));
|
|
133772
|
+
function matchNamedCron(target, project, rows) {
|
|
133769
133773
|
const matches = rows.filter((row) => row.name === target);
|
|
133770
133774
|
if (matches.length === 0) {
|
|
133771
133775
|
throw new Error(`CRON_NOT_FOUND: No scheduled task named "${target}" was found${project ? ` in project "${project}"` : ""}.`);
|
|
@@ -133778,6 +133782,20 @@ async function findNamedCronRow(target, explicit, signal) {
|
|
|
133778
133782
|
throw new Error("cron_list returned a scheduled task without a cron_id.");
|
|
133779
133783
|
return { ...matches[0], cron_id: id };
|
|
133780
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
|
+
}
|
|
133781
133799
|
async function resolveCronId(target, explicit) {
|
|
133782
133800
|
if (target.startsWith("cron_"))
|
|
133783
133801
|
return target;
|
|
@@ -133844,20 +133862,18 @@ function printCronMutation(verb, value) {
|
|
|
133844
133862
|
const id = isRecord(data2) && typeof data2.id === "string" ? data2.id : isRecord(data2) && typeof data2.cron_id === "string" ? data2.cron_id : null;
|
|
133845
133863
|
success(`${verb}${id ? ` ${id}` : ""}.`);
|
|
133846
133864
|
}
|
|
133847
|
-
async function runCronInPreview(cronId, opts, timeoutSeconds) {
|
|
133865
|
+
async function runCronInPreview(client, cronId, opts, timeoutSeconds) {
|
|
133848
133866
|
const tool = await folderPreviewTool({});
|
|
133849
133867
|
const version2 = await previewCurrentVersion(tool.credential);
|
|
133850
133868
|
let firstDelayMs = 0;
|
|
133851
|
-
const
|
|
133852
|
-
allTools: true,
|
|
133869
|
+
const result = cronRunResult(await client.call("POST", `/cron/${encodeURIComponent(cronId)}/run-preview`, version2, void 0, {
|
|
133853
133870
|
onRetryAfter: /* @__PURE__ */ __name((ms2) => {
|
|
133854
|
-
firstDelayMs =
|
|
133871
|
+
firstDelayMs = ms2;
|
|
133855
133872
|
}, "onRetryAfter")
|
|
133856
|
-
});
|
|
133857
|
-
const result = cronRunResult(value);
|
|
133873
|
+
}));
|
|
133858
133874
|
if (!opts.wait) {
|
|
133859
133875
|
if (opts.json) {
|
|
133860
|
-
printJson(
|
|
133876
|
+
printJson({ ok: true, data: result });
|
|
133861
133877
|
return;
|
|
133862
133878
|
}
|
|
133863
133879
|
success(`Scheduled task queued in preview ${version2.preview_session_id} (not finished yet). Job ${result.job_id}.`);
|
|
@@ -133866,7 +133882,7 @@ async function runCronInPreview(cronId, opts, timeoutSeconds) {
|
|
|
133866
133882
|
}
|
|
133867
133883
|
if (!opts.json)
|
|
133868
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`));
|
|
133869
|
-
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);
|
|
133870
133886
|
const succeeded = !timedOut && job.status === JOB_SUCCESS_STATUS;
|
|
133871
133887
|
if (!succeeded)
|
|
133872
133888
|
process.exitCode = 1;
|
|
@@ -133941,38 +133957,37 @@ zone each trigger is stored in, and \`cron update --schedule\` keeps that zone u
|
|
|
133941
133957
|
if (opts.timeout !== void 0 && !opts.wait) {
|
|
133942
133958
|
throw new Error("USAGE_ERROR: --timeout only applies with --wait.");
|
|
133943
133959
|
}
|
|
133944
|
-
const
|
|
133960
|
+
const client = new ApiClient(getToken());
|
|
133961
|
+
const cronId = await resolveRunCronId(client, target, opts.project);
|
|
133945
133962
|
if (opts.preview) {
|
|
133946
133963
|
if (opts.twice) {
|
|
133947
133964
|
await printPreviewScheduleTest(cronId, await folderPreviewTool({}), true, Boolean(opts.json));
|
|
133948
133965
|
return;
|
|
133949
133966
|
}
|
|
133950
|
-
await runCronInPreview(cronId, opts, timeoutSeconds);
|
|
133967
|
+
await runCronInPreview(client, cronId, opts, timeoutSeconds);
|
|
133951
133968
|
return;
|
|
133952
133969
|
}
|
|
133953
133970
|
let firstDelayMs = 0;
|
|
133954
|
-
const value = await
|
|
133955
|
-
allTools: true,
|
|
133971
|
+
const value = await client.call("POST", `/cron/${encodeURIComponent(cronId)}/run`, void 0, void 0, {
|
|
133956
133972
|
onRetryAfter: /* @__PURE__ */ __name((ms2) => {
|
|
133957
|
-
firstDelayMs =
|
|
133973
|
+
firstDelayMs = ms2;
|
|
133958
133974
|
}, "onRetryAfter")
|
|
133959
133975
|
});
|
|
133960
133976
|
queued = true;
|
|
133977
|
+
const result = cronRunResult(value);
|
|
133961
133978
|
if (!opts.wait) {
|
|
133962
133979
|
if (opts.json) {
|
|
133963
|
-
printJson(
|
|
133980
|
+
printJson({ ok: true, data: result });
|
|
133964
133981
|
return;
|
|
133965
133982
|
}
|
|
133966
|
-
|
|
133967
|
-
|
|
133968
|
-
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}`));
|
|
133969
133985
|
console.log(dim("Pass --wait to wait for the run to finish and see its result."));
|
|
133970
133986
|
return;
|
|
133971
133987
|
}
|
|
133972
|
-
const result = cronRunResult(value);
|
|
133973
133988
|
if (!opts.json)
|
|
133974
133989
|
console.log(dim(`Job ${result.job_id} queued for cron ${result.cron_id}; waiting up to ${timeoutSeconds}s\u2026`));
|
|
133975
|
-
const { job, timedOut } = await waitForJob(result, timeoutSeconds, firstDelayMs);
|
|
133990
|
+
const { job, timedOut } = await waitForJob(client, result, timeoutSeconds, firstDelayMs);
|
|
133976
133991
|
const succeeded = !timedOut && job.status === JOB_SUCCESS_STATUS;
|
|
133977
133992
|
if (!succeeded)
|
|
133978
133993
|
process.exitCode = 1;
|
|
@@ -134115,6 +134130,7 @@ var init_cron = __esm({
|
|
|
134115
134130
|
init_next_actions();
|
|
134116
134131
|
init_platform_tools();
|
|
134117
134132
|
init_poll_delay();
|
|
134133
|
+
init_preview_credential();
|
|
134118
134134
|
init_preview_jobs();
|
|
134119
134135
|
init_platform_command();
|
|
134120
134136
|
init_output();
|
|
@@ -134142,7 +134158,9 @@ var init_cron = __esm({
|
|
|
134142
134158
|
__name(cronRunUnavailable, "cronRunUnavailable");
|
|
134143
134159
|
__name(printTypedCronError, "printTypedCronError");
|
|
134144
134160
|
__name(cronProjectScope, "cronProjectScope");
|
|
134161
|
+
__name(matchNamedCron, "matchNamedCron");
|
|
134145
134162
|
__name(findNamedCronRow, "findNamedCronRow");
|
|
134163
|
+
__name(resolveRunCronId, "resolveRunCronId");
|
|
134146
134164
|
__name(resolveCronId, "resolveCronId");
|
|
134147
134165
|
__name(findCronRow, "findCronRow");
|
|
134148
134166
|
__name(nextRunLabel, "nextRunLabel");
|