@qodalis/cli-server-jobs 2.3.0 → 2.4.0

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.
@@ -3320,6 +3320,24 @@ var jobs = (() => {
3320
3320
  if (diff < 864e5) return `${Math.round(diff / 36e5)}h ago`;
3321
3321
  return `${Math.round(diff / 864e5)}d ago`;
3322
3322
  }
3323
+ function formatSpan(value) {
3324
+ if (value === null || value === void 0 || value === "") return null;
3325
+ if (typeof value === "string") return value;
3326
+ if (!Number.isFinite(value) || value < 0) return null;
3327
+ const units = [[864e5, "d"], [36e5, "h"], [6e4, "m"], [1e3, "s"]];
3328
+ for (const [size, unit] of units) {
3329
+ if (value >= size && value % size === 0) return `${value / size}${unit}`;
3330
+ }
3331
+ return value >= 1e3 ? `${(value / 1e3).toFixed(1)}s` : `${value}ms`;
3332
+ }
3333
+ function formatRunning(job) {
3334
+ const running = job.runningExecutionIds?.length ?? (job.currentExecutionId ? 1 : 0);
3335
+ const max = job.maxConcurrentRuns ?? 1;
3336
+ if (running === 0 && !job.queued) return null;
3337
+ const parts = [max > 1 ? `${running}/${max} running` : `${running} running`];
3338
+ if (job.queued) parts.push("1 queued");
3339
+ return parts.join(", ");
3340
+ }
3323
3341
  function formatDuration(ms) {
3324
3342
  if (ms == null) return "-";
3325
3343
  if (ms < 1e3) return `${ms}ms`;
@@ -3685,6 +3703,11 @@ var jobs = (() => {
3685
3703
  t.t("cli.server.jobs.edit.help.change_job_step_step", "Change a job step by step: description, group, cron schedule or interval, max retries, timeout and overlap policy (skip, queue or cancel). Press Enter to keep a value and Ctrl+C or Escape to cancel; nothing changes until you confirm. A job on several servers needs --server.")
3686
3704
  );
3687
3705
  context.writer.writeln();
3706
+ writeWrapped(
3707
+ context,
3708
+ t.t("cli.server.jobs.edit.help.max_concurrent_runs", "Max concurrent runs: how many runs of the job may go at the same time (1 by default). When that many are running, the overlap policy decides what happens to the next one.")
3709
+ );
3710
+ context.writer.writeln();
3688
3711
  writeUsage(context, [
3689
3712
  ["server jobs edit <name|id>", ""]
3690
3713
  ]);
@@ -3776,7 +3799,7 @@ var jobs = (() => {
3776
3799
  j.name,
3777
3800
  j.group ?? "-",
3778
3801
  statusColor(j.status, context.writer),
3779
- j.schedule ?? (j.interval ? `every ${j.interval}ms` : "-"),
3802
+ j.schedule ?? (formatSpan(j.interval) ? `every ${formatSpan(j.interval)}` : "-"),
3780
3803
  formatRelativeTime(j.lastRunAt),
3781
3804
  formatRelativeTime(j.nextRunAt),
3782
3805
  formatDuration(j.lastRunDuration)
@@ -3814,12 +3837,16 @@ var jobs = (() => {
3814
3837
  ["Status", statusColor(job.status, context.writer)],
3815
3838
  [
3816
3839
  "Schedule",
3817
- job.schedule ?? (job.interval ? `every ${job.interval}ms` : "-")
3840
+ job.schedule ?? (formatSpan(job.interval) ? `every ${formatSpan(job.interval)}` : "-")
3818
3841
  ],
3819
3842
  ["Max Retries", String(job.maxRetries)],
3820
- ["Timeout", job.timeout ? `${job.timeout}ms` : "none"],
3843
+ ["Timeout", formatSpan(job.timeout) ?? "none"],
3821
3844
  ["Overlap Policy", job.overlapPolicy],
3822
- ["Current Execution", job.currentExecutionId ?? "none"],
3845
+ ["Max Concurrent Runs", String(job.maxConcurrentRuns ?? 1)],
3846
+ [
3847
+ "Running",
3848
+ job.runningExecutionIds && job.runningExecutionIds.length > 1 ? `${formatRunning(job)}: ${job.runningExecutionIds.join(", ")}` : formatRunning(job) && job.currentExecutionId ? `${formatRunning(job)} (${job.currentExecutionId})` : formatRunning(job) ?? "none"
3849
+ ],
3823
3850
  ["Next Run", formatRelativeTime(job.nextRunAt)],
3824
3851
  ["Last Run", formatRelativeTime(job.lastRunAt)],
3825
3852
  [
@@ -4063,7 +4090,7 @@ var jobs = (() => {
4063
4090
  const newGroup = await ask(`Group [${job.group ?? "none"}]: `);
4064
4091
  if (newGroup == null) return cancelled();
4065
4092
  if (newGroup) update.group = newGroup;
4066
- const currentSchedule = job.schedule ?? (job.interval ? `interval: ${job.interval}ms` : "none");
4093
+ const currentSchedule = job.schedule ?? (formatSpan(job.interval) ? `interval: ${formatSpan(job.interval)}` : "none");
4067
4094
  const newSchedule = await ask(
4068
4095
  `Cron schedule [${currentSchedule}]: `
4069
4096
  );
@@ -4071,7 +4098,7 @@ var jobs = (() => {
4071
4098
  if (newSchedule) update.schedule = newSchedule;
4072
4099
  if (!newSchedule) {
4073
4100
  const newInterval = await ask(
4074
- `Interval (e.g. 30s, 5m) [${job.interval ? `${job.interval}ms` : "none"}]: `
4101
+ `Interval (e.g. 30s, 5m) [${formatSpan(job.interval) ?? "none"}]: `
4075
4102
  );
4076
4103
  if (newInterval == null) return cancelled();
4077
4104
  if (newInterval) update.interval = newInterval;
@@ -4085,7 +4112,7 @@ var jobs = (() => {
4085
4112
  }
4086
4113
  }
4087
4114
  const newTimeout = await ask(
4088
- `Timeout (e.g. 5m, 1h) [${job.timeout ? `${job.timeout}ms` : "none"}]: `
4115
+ `Timeout (e.g. 5m, 1h) [${formatSpan(job.timeout) ?? "none"}]: `
4089
4116
  );
4090
4117
  if (newTimeout == null) return cancelled();
4091
4118
  if (newTimeout) update.timeout = newTimeout;
@@ -4096,6 +4123,20 @@ var jobs = (() => {
4096
4123
  if (newOverlap && ["skip", "queue", "cancel"].includes(newOverlap.toLowerCase())) {
4097
4124
  update.overlapPolicy = newOverlap.toLowerCase();
4098
4125
  }
4126
+ const newMax = await ask(
4127
+ `Max concurrent runs [${job.maxConcurrentRuns ?? 1}]: `
4128
+ );
4129
+ if (newMax == null) return cancelled();
4130
+ if (newMax) {
4131
+ const parsed = Number(newMax);
4132
+ if (Number.isInteger(parsed) && parsed >= 1) {
4133
+ update.maxConcurrentRuns = parsed;
4134
+ } else {
4135
+ context.writer.writeWarning(
4136
+ "Max concurrent runs must be a whole number of at least 1; kept as it was."
4137
+ );
4138
+ }
4139
+ }
4099
4140
  if (Object.keys(update).length === 0) {
4100
4141
  context.writer.writeInfo("No changes made.");
4101
4142
  return;