@xeplr/ui-jobs 1.6.5 → 1.6.6

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/README.md CHANGED
@@ -130,6 +130,7 @@ Three steps (four with `chainsApiBase`), all reachable at any time, with **Save
130
130
  1. **Job** — name, description, action.
131
131
  2. **Inputs** — a control per field of the action's `inputSchema`: a select for `options`, true/false for `boolean`, a number input, a JSON textarea for `object` / `array` (invalid JSON blocks the save), text otherwise. Fields marked `system: true` are never shown — the server fills them, and rendering them would ask for a credential. Optional fields with a `default` are under **Advanced**, whose summary lists their values. Values are converted to the declared types on save, since `@xeplr/schema-handler` rejects `"1000"` for a number.
132
132
  3. **Schedule** — cron (`CronScheduleField`), status, **Start from** (`startAt`), **Retry on failure** (0–3, default 0), **Give up after** (`timeoutMinutes`, blank = server default of 30).
133
+ **Each run takes** (only for an action with a `window` input) — which rows each run takes, the job's decision (`incrementalMode`): *Everything, each run* (none), *Since the last successful run* (`period`), or *Continue from what is already loaded* (`watermark`, offered only when the action's `window` field says `watermark: true`, since the action has to read its own target). With `watermark`, **Also re-read the last … days** (`reloadDays`). A range given when the job is started always wins. Logic in `src/lib/incrementalModel.js`.
133
134
  4. **After this job** (`JobChainSection`, `useJobChainController`, `lib/jobChainModel.js`) — "Run another job when this one finishes", then rules checked top to bottom, first match wins. Each rule has:
134
135
  - **If**: a JSON condition, e.g. `{ "field": "status", "op": "=", "value": "success" }`, or `{ "all": [ … ] }` / `{ "any": [ … ] }`. Empty means "otherwise" and must come last.
135
136
  - **Run**: another job.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-jobs",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "description": "The screens for @xeplr/jobs — schedule, run, pause and watch jobs — as routes a host app registers, or a standalone app",
5
5
  "type": "module",
6
6
  "main": "src/index.jsx",
@@ -0,0 +1,57 @@
1
+ // WHICH ROWS EACH RUN TAKES — the job's decision (@xeplr/jobs'
2
+ // incrementalMode and reloadDays), not the action's.
3
+ //
4
+ // Offered only for an action that takes a date range: one whose inputSchema
5
+ // has a `window` field. "Continue from what is already loaded" needs the
6
+ // action to read its own target, so it is offered only when that field says
7
+ // it can (`watermark: true`, as BI's move-run does). An action that never
8
+ // declared it would be handed a word it does not know.
9
+ //
10
+ // Pure: no React.
11
+
12
+ export const NONE = ''
13
+
14
+ /** The `window` field of an action, or null when it takes no range. */
15
+ export function windowField(action) {
16
+ return ((action && action.inputSchema) || []).find((f) => f && f.name === 'window') || null
17
+ }
18
+
19
+ /** The choices this action allows, in the order they are shown. */
20
+ export function incrementalChoices(action) {
21
+ const field = windowField(action)
22
+ if (!field) return []
23
+ const out = [
24
+ { value: NONE, label: 'Everything, each run', help: 'No range is worked out: each run takes what its inputs say.' },
25
+ { value: 'period', label: 'Since the last successful run', help: 'Each run covers from where the last successful one stopped, up to now. A failed run is picked up by the next.' }
26
+ ]
27
+ if (field.watermark) {
28
+ out.push({ value: 'watermark', label: 'Continue from what is already loaded', help: 'Each run reads the highest value the target already holds and takes everything after it.' })
29
+ }
30
+ return out
31
+ }
32
+
33
+ /** The two fields as the form holds them: mode, and days as text. */
34
+ export function incrementalDraft(job) {
35
+ return {
36
+ incrementalMode: (job && job.incrementalMode) || NONE,
37
+ reloadDays: job && job.reloadDays ? String(job.reloadDays) : ''
38
+ }
39
+ }
40
+
41
+ /**
42
+ * What is saved. A mode the action no longer allows (the action was changed)
43
+ * is cleared rather than kept; reloadDays belongs to 'watermark' only.
44
+ * Returns { body } or { problem } in words.
45
+ */
46
+ export function incrementalBody(draft, action) {
47
+ const allowed = incrementalChoices(action).map((c) => c.value)
48
+ const mode = allowed.includes(draft.incrementalMode) ? draft.incrementalMode : NONE
49
+ if (mode !== 'watermark') return { body: { incrementalMode: mode || null, reloadDays: null } }
50
+ const text = String(draft.reloadDays == null ? '' : draft.reloadDays).trim()
51
+ if (text === '') return { body: { incrementalMode: mode, reloadDays: null } }
52
+ const days = Number(text)
53
+ if (!Number.isInteger(days) || days < 1) {
54
+ return { problem: 'Re-read the last … days takes a whole number of days, 1 or more — or leave it empty.' }
55
+ }
56
+ return { body: { incrementalMode: mode, reloadDays: days } }
57
+ }
@@ -17,6 +17,7 @@ import { useRunContract } from '../useRunContract.js'
17
17
  import { useJobsUrl } from '../useJobsUrl.js'
18
18
  import { useJobChainController } from '../useJobChainController.js'
19
19
  import { acceptableFields } from '../lib/jobChainModel.js'
20
+ import { incrementalChoices, incrementalDraft, incrementalBody } from '../lib/incrementalModel.js'
20
21
  import './Jobs.css'
21
22
 
22
23
  // SCHEDULED JOBS — @xeplr/jobs, in this product's chrome.
@@ -515,7 +516,9 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
515
516
  // Inputs the job BEFORE this one in a chain may fill (@xeplr/jobs'
516
517
  // acceptsInputs). No longer edited here — a job takes what it needs from
517
518
  // the job before through its parameters — but kept as saved.
518
- acceptsInputs: Array.isArray(job?.acceptsInputs) ? job.acceptsInputs : []
519
+ acceptsInputs: Array.isArray(job?.acceptsInputs) ? job.acceptsInputs : [],
520
+ // WHICH ROWS EACH RUN TAKES — the job's decision (see incrementalModel).
521
+ ...incrementalDraft(job)
519
522
  }))
520
523
  const [saving, setSaving] = useState(false)
521
524
  const chain = useJobChainController(job?.id || null)
@@ -539,6 +542,12 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
539
542
  raiseSnackbar(`Not valid JSON: ${broken.join(', ')}`, { design: 'error' })
540
543
  return
541
544
  }
545
+ const incremental = incrementalBody(draft, action)
546
+ if (incremental.problem) {
547
+ setStep(2)
548
+ raiseSnackbar(incremental.problem, { design: 'error' })
549
+ return
550
+ }
542
551
  // The rules are checked BEFORE anything is saved, so a typo in one does
543
552
  // not leave a job saved and its chain not.
544
553
  const chainCheck = chain.check(job?.id)
@@ -579,7 +588,8 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
579
588
  // strings is what made every number/boolean field fail validation.
580
589
  inputs: fromFieldValues(action, draft.inputs),
581
590
  // Only names that are still fields of the chosen action.
582
- acceptsInputs: draft.acceptsInputs.filter((n) => acceptableFields(fields).some((f) => f.name === n))
591
+ acceptsInputs: draft.acceptsInputs.filter((n) => acceptableFields(fields).some((f) => f.name === n)),
592
+ ...incremental.body
583
593
  })
584
594
  if (!job?.id) {
585
595
  const newId = res && Array.isArray(res.updatedIds) ? res.updatedIds[0] : null
@@ -756,6 +766,38 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
756
766
  </div>
757
767
  )}
758
768
 
769
+ {/* WHICH ROWS EACH RUN TAKES — only for an action that takes a range.
770
+ The job decides this, not the action: the same movement can run
771
+ nightly "since the last run" and by hand for one month. */}
772
+ {incrementalChoices(action).length > 0 && (() => {
773
+ const choices = incrementalChoices(action)
774
+ const on = choices.find((c) => c.value === draft.incrementalMode) || choices[0]
775
+ return (
776
+ <>
777
+ <div className="jb-field">
778
+ <label htmlFor="jb-incremental">Each run takes</label>
779
+ <select id="jb-incremental" value={on.value} onChange={(e) => patch({ incrementalMode: e.target.value })}>
780
+ {choices.map((c) => <option key={c.value} value={c.value}>{c.label}</option>)}
781
+ </select>
782
+ <span className="jb-help">
783
+ {on.help} A range given when it is started (by a workflow, or by the job before it) always wins.
784
+ </span>
785
+ </div>
786
+ {on.value === 'watermark' && (
787
+ <div className="jb-field">
788
+ <label htmlFor="jb-reload">Also re-read the last</label>
789
+ <input id="jb-reload" type="number" min="1" step="1" placeholder="—"
790
+ value={draft.reloadDays} onChange={(e) => patch({ reloadDays: e.target.value })} />
791
+ <span className="jb-help">
792
+ Days. Rows changed after they were loaded (a late payment, an edited order) are below the highest
793
+ value, so they are only picked up by re-reading. Empty: no re-read.
794
+ </span>
795
+ </div>
796
+ )}
797
+ </>
798
+ )
799
+ })()}
800
+
759
801
  {/* RETRY — off by default. An action that failed once usually fails
760
802
  again, and silently re-running something that moves data is worse
761
803
  than leaving it failed and visible. */}