@xeplr/ui-jobs 1.6.4 → 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 +1 -0
- package/package.json +2 -2
- package/src/lib/incrementalModel.js +57 -0
- package/src/pages/Jobs.jsx +47 -29
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.
|
|
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",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@vitejs/plugin-react": "^5.2.0",
|
|
49
49
|
"@xeplr/ui-account": "^1.0.2",
|
|
50
|
-
"@xeplr/ui-utils": "^1.1.
|
|
50
|
+
"@xeplr/ui-utils": "^1.1.5",
|
|
51
51
|
"react": "^19.2.4",
|
|
52
52
|
"react-dom": "^19.2.4",
|
|
53
53
|
"react-router-dom": "^7.13.2",
|
|
@@ -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
|
+
}
|
package/src/pages/Jobs.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, useCallback, useEffect, useMemo, useState } from 'react'
|
|
2
|
-
import { raiseConfirm, raiseSnackbar } from '@xeplr/ui-utils'
|
|
2
|
+
import { fieldLabel, raiseConfirm, raiseSnackbar } from '@xeplr/ui-utils'
|
|
3
3
|
import { relativeTime } from './relativeTime.js'
|
|
4
4
|
import {
|
|
5
5
|
listJobs, listOccurrences, listJobOccurrences, listJobActions, listActiveRuns,
|
|
@@ -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.
|
|
@@ -288,32 +289,8 @@ function visibleFields(action, inputs) {
|
|
|
288
289
|
}
|
|
289
290
|
|
|
290
291
|
// ── labels ────────────────────────────────────────────────────────────────
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
// "connectionInfoId", "dbInfoId", "streaming_mode" and "batchSize" in front of
|
|
294
|
-
// people as though those were English.
|
|
295
|
-
//
|
|
296
|
-
// A schema may carry its own `label`; this is the fallback, and it is good
|
|
297
|
-
// enough that most fields will never need one. `Id`/`Info` are suffixes of the
|
|
298
|
-
// storage, not of the thing — you pick a Connection, not a connectionInfoId.
|
|
299
|
-
const LABEL_WORDS = { db: 'Database', sql: 'SQL', url: 'URL', id: 'ID', api: 'API' }
|
|
300
|
-
|
|
301
|
-
function fieldLabel(field) {
|
|
302
|
-
if (field.label) return field.label
|
|
303
|
-
return String(field.name)
|
|
304
|
-
.replace(/Id$/, '')
|
|
305
|
-
.replace(/Info$/, '')
|
|
306
|
-
.replace(/[_-]+/g, ' ')
|
|
307
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
308
|
-
.trim()
|
|
309
|
-
.split(' ')
|
|
310
|
-
.map((w, i) => {
|
|
311
|
-
const known = LABEL_WORDS[w.toLowerCase()]
|
|
312
|
-
if (known) return known
|
|
313
|
-
return i === 0 ? w.charAt(0).toUpperCase() + w.slice(1) : w.toLowerCase()
|
|
314
|
-
})
|
|
315
|
-
.join(' ')
|
|
316
|
-
}
|
|
292
|
+
// A field's name as words ("connectionInfoId" → "Connection") is
|
|
293
|
+
// @xeplr/ui-utils' fieldLabel, shared with X-Flow's step editor.
|
|
317
294
|
|
|
318
295
|
/**
|
|
319
296
|
* Split the fields into what you fill in and what you almost never touch.
|
|
@@ -539,7 +516,9 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
|
|
|
539
516
|
// Inputs the job BEFORE this one in a chain may fill (@xeplr/jobs'
|
|
540
517
|
// acceptsInputs). No longer edited here — a job takes what it needs from
|
|
541
518
|
// the job before through its parameters — but kept as saved.
|
|
542
|
-
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)
|
|
543
522
|
}))
|
|
544
523
|
const [saving, setSaving] = useState(false)
|
|
545
524
|
const chain = useJobChainController(job?.id || null)
|
|
@@ -563,6 +542,12 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
|
|
|
563
542
|
raiseSnackbar(`Not valid JSON: ${broken.join(', ')}`, { design: 'error' })
|
|
564
543
|
return
|
|
565
544
|
}
|
|
545
|
+
const incremental = incrementalBody(draft, action)
|
|
546
|
+
if (incremental.problem) {
|
|
547
|
+
setStep(2)
|
|
548
|
+
raiseSnackbar(incremental.problem, { design: 'error' })
|
|
549
|
+
return
|
|
550
|
+
}
|
|
566
551
|
// The rules are checked BEFORE anything is saved, so a typo in one does
|
|
567
552
|
// not leave a job saved and its chain not.
|
|
568
553
|
const chainCheck = chain.check(job?.id)
|
|
@@ -603,7 +588,8 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
|
|
|
603
588
|
// strings is what made every number/boolean field fail validation.
|
|
604
589
|
inputs: fromFieldValues(action, draft.inputs),
|
|
605
590
|
// Only names that are still fields of the chosen action.
|
|
606
|
-
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
|
|
607
593
|
})
|
|
608
594
|
if (!job?.id) {
|
|
609
595
|
const newId = res && Array.isArray(res.updatedIds) ? res.updatedIds[0] : null
|
|
@@ -780,6 +766,38 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
|
|
|
780
766
|
</div>
|
|
781
767
|
)}
|
|
782
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
|
+
|
|
783
801
|
{/* RETRY — off by default. An action that failed once usually fails
|
|
784
802
|
again, and silently re-running something that moves data is worse
|
|
785
803
|
than leaving it failed and visible. */}
|