@milabench/bujang 0.0.0-stage → 0.1.2
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 +108 -2
- package/dist/api.d.ts +151 -0
- package/dist/components/AutocompleteInput.d.ts +15 -0
- package/dist/components/MonacoEditor.d.ts +11 -0
- package/dist/components/toaster.d.ts +2 -0
- package/dist/components/tooltip.d.ts +11 -0
- package/dist/constants.d.ts +3 -0
- package/dist/context.d.ts +44 -0
- package/dist/hooks/useColorMode.d.ts +4 -0
- package/dist/hooks/usePageTitle.d.ts +2 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +5036 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +26 -0
- package/dist/routes.d.ts +22 -0
- package/dist/theme.css +72 -0
- package/dist/toast.d.ts +18 -0
- package/dist/types.d.ts +474 -0
- package/dist/views/AgentActivityView.d.ts +8 -0
- package/dist/views/JobDetails.d.ts +2 -0
- package/dist/views/JobLogs.d.ts +4 -0
- package/dist/views/JobSubmit.d.ts +22 -0
- package/dist/views/JobSubmitView.d.ts +2 -0
- package/dist/views/JobsView.d.ts +4 -0
- package/dist/views/LogDisplay.d.ts +11 -0
- package/dist/views/PipelinesView.d.ts +2 -0
- package/dist/views/ScheduledJobsView.d.ts +2 -0
- package/package.json +70 -4
- package/src/api.ts +602 -0
- package/src/components/AutocompleteInput.tsx +253 -0
- package/src/components/MonacoEditor.tsx +163 -0
- package/src/components/toaster.tsx +38 -0
- package/src/components/tooltip.tsx +52 -0
- package/src/constants.ts +3 -0
- package/src/context.tsx +106 -0
- package/src/hooks/useColorMode.ts +31 -0
- package/src/hooks/usePageTitle.ts +21 -0
- package/src/index.ts +33 -0
- package/src/paths.ts +71 -0
- package/src/routes.tsx +55 -0
- package/src/theme.css +72 -0
- package/src/toast.ts +35 -0
- package/src/types.ts +542 -0
- package/src/views/AgentActivityView.tsx +262 -0
- package/src/views/JobDetails.tsx +675 -0
- package/src/views/JobLogs.tsx +987 -0
- package/src/views/JobSubmit.tsx +1272 -0
- package/src/views/JobSubmitView.tsx +69 -0
- package/src/views/JobsView.tsx +736 -0
- package/src/views/LogDisplay.tsx +171 -0
- package/src/views/PipelinesView.tsx +1318 -0
- package/src/views/ScheduledJobsView.tsx +735 -0
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Box,
|
|
4
|
+
VStack,
|
|
5
|
+
HStack,
|
|
6
|
+
Heading,
|
|
7
|
+
Text,
|
|
8
|
+
Button,
|
|
9
|
+
Badge,
|
|
10
|
+
Table,
|
|
11
|
+
Spinner,
|
|
12
|
+
Card,
|
|
13
|
+
Grid,
|
|
14
|
+
Code,
|
|
15
|
+
Link,
|
|
16
|
+
Dialog,
|
|
17
|
+
Input,
|
|
18
|
+
Field,
|
|
19
|
+
NativeSelect,
|
|
20
|
+
Textarea,
|
|
21
|
+
} from '@chakra-ui/react';
|
|
22
|
+
import { Link as RouterLink } from 'react-router-dom';
|
|
23
|
+
import { useBujangPaths } from '../context';
|
|
24
|
+
import { LuPlay, LuTrash2, LuPower, LuChevronDown, LuChevronRight, LuCircleAlert, LuPencil, LuRefreshCw } from 'react-icons/lu';
|
|
25
|
+
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
26
|
+
import { toaster } from '../toast';
|
|
27
|
+
import { Tooltip } from '../components/tooltip';
|
|
28
|
+
import { MonacoEditor } from '../components/MonacoEditor';
|
|
29
|
+
import {
|
|
30
|
+
getScheduledJobs,
|
|
31
|
+
deleteScheduledJob,
|
|
32
|
+
toggleScheduledJob,
|
|
33
|
+
runScheduledJobNow,
|
|
34
|
+
getScheduledJobRuns,
|
|
35
|
+
updateScheduledJob,
|
|
36
|
+
getScheduledJobTemplateDiff,
|
|
37
|
+
syncScheduledJobTemplate,
|
|
38
|
+
getSlurmTemplates,
|
|
39
|
+
} from '../api';
|
|
40
|
+
import type { ScheduledJob, ScheduledJobRun, ScheduledJobTemplateDiff } from '../types';
|
|
41
|
+
|
|
42
|
+
const CRON_PRESETS: { label: string; cron: string }[] = [
|
|
43
|
+
{ label: 'Daily at midnight', cron: '0 0 * * *' },
|
|
44
|
+
{ label: 'Weekly on Sunday at 2am', cron: '0 2 * * 0' },
|
|
45
|
+
{ label: 'Monthly on the 1st', cron: '0 0 1 * *' },
|
|
46
|
+
{ label: 'Weekdays at midnight', cron: '0 0 * * 1-5' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
function formatDate(iso: string | null | undefined): string {
|
|
50
|
+
if (!iso) return '—';
|
|
51
|
+
return new Date(iso + 'Z').toLocaleString();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function cronHumanLabel(cron: string): string {
|
|
55
|
+
const match = CRON_PRESETS.find(p => p.cron === cron);
|
|
56
|
+
return match ? match.label : cron;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ─── Run history sub-component ──────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
const RunHistory: React.FC<{ jobId: number }> = ({ jobId }) => {
|
|
62
|
+
const paths = useBujangPaths();
|
|
63
|
+
const { data: runs, isLoading } = useQuery<ScheduledJobRun[]>({
|
|
64
|
+
queryKey: ['scheduled-runs', jobId],
|
|
65
|
+
queryFn: () => getScheduledJobRuns(jobId),
|
|
66
|
+
refetchInterval: 30_000,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (isLoading) return <Spinner size="sm" />;
|
|
70
|
+
if (!runs || runs.length === 0)
|
|
71
|
+
return <Text fontSize="sm" color="var(--color-text-muted)" fontStyle="italic">No runs yet.</Text>;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Table.Root size="sm" variant="outline">
|
|
75
|
+
<Table.Header>
|
|
76
|
+
<Table.Row>
|
|
77
|
+
<Table.ColumnHeader>Submitted</Table.ColumnHeader>
|
|
78
|
+
<Table.ColumnHeader>Status</Table.ColumnHeader>
|
|
79
|
+
<Table.ColumnHeader>Job Runner ID</Table.ColumnHeader>
|
|
80
|
+
<Table.ColumnHeader>Error</Table.ColumnHeader>
|
|
81
|
+
</Table.Row>
|
|
82
|
+
</Table.Header>
|
|
83
|
+
<Table.Body>
|
|
84
|
+
{runs.map((r) => (
|
|
85
|
+
<Table.Row key={r._id}>
|
|
86
|
+
<Table.Cell>{formatDate(r.submitted_at)}</Table.Cell>
|
|
87
|
+
<Table.Cell>
|
|
88
|
+
<Badge colorPalette={r.status === 'submitted' ? 'green' : 'red'} variant="subtle">
|
|
89
|
+
{r.status}
|
|
90
|
+
</Badge>
|
|
91
|
+
</Table.Cell>
|
|
92
|
+
<Table.Cell fontSize="xs" fontFamily="mono">
|
|
93
|
+
{r.jr_job_id && r.slurm_job_id ? (
|
|
94
|
+
<Link asChild colorPalette="blue">
|
|
95
|
+
<RouterLink to={paths.jobLogs(r.slurm_job_id, r.jr_job_id)}>
|
|
96
|
+
{r.jr_job_id}
|
|
97
|
+
</RouterLink>
|
|
98
|
+
</Link>
|
|
99
|
+
) : (
|
|
100
|
+
r.jr_job_id || '—'
|
|
101
|
+
)}
|
|
102
|
+
</Table.Cell>
|
|
103
|
+
<Table.Cell>
|
|
104
|
+
{r.error ? (
|
|
105
|
+
<Tooltip
|
|
106
|
+
content={
|
|
107
|
+
<Box
|
|
108
|
+
as="pre"
|
|
109
|
+
fontSize="xs"
|
|
110
|
+
fontFamily="mono"
|
|
111
|
+
whiteSpace="pre-wrap"
|
|
112
|
+
wordBreak="break-all"
|
|
113
|
+
maxW="500px"
|
|
114
|
+
maxH="300px"
|
|
115
|
+
overflowY="auto"
|
|
116
|
+
>
|
|
117
|
+
{r.error}
|
|
118
|
+
</Box>
|
|
119
|
+
}
|
|
120
|
+
showArrow
|
|
121
|
+
openDelay={200}
|
|
122
|
+
>
|
|
123
|
+
<Button variant="ghost" size="xs" colorPalette="red">
|
|
124
|
+
<LuCircleAlert />
|
|
125
|
+
Error
|
|
126
|
+
</Button>
|
|
127
|
+
</Tooltip>
|
|
128
|
+
) : '—'}
|
|
129
|
+
</Table.Cell>
|
|
130
|
+
</Table.Row>
|
|
131
|
+
))}
|
|
132
|
+
</Table.Body>
|
|
133
|
+
</Table.Root>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// ─── Template sync dialog ───────────────────────────────────────────
|
|
138
|
+
// Shown when a job's source template has changed on disk since it was
|
|
139
|
+
// last loaded, so the change can be reviewed before it's applied instead
|
|
140
|
+
// of silently overwriting a scheduled job's script.
|
|
141
|
+
|
|
142
|
+
const TemplateSyncDialog: React.FC<{
|
|
143
|
+
job: ScheduledJob | null;
|
|
144
|
+
onClose: () => void;
|
|
145
|
+
}> = ({ job, onClose }) => {
|
|
146
|
+
const queryClient = useQueryClient();
|
|
147
|
+
|
|
148
|
+
const { data: diff, isLoading, error } = useQuery<ScheduledJobTemplateDiff>({
|
|
149
|
+
queryKey: ['scheduled-template-diff', job?._id],
|
|
150
|
+
queryFn: () => getScheduledJobTemplateDiff(job!._id),
|
|
151
|
+
enabled: job != null,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const syncMut = useMutation({
|
|
155
|
+
mutationFn: () => syncScheduledJobTemplate(job!._id),
|
|
156
|
+
onSuccess: () => {
|
|
157
|
+
queryClient.invalidateQueries({ queryKey: ['scheduled-jobs'] });
|
|
158
|
+
toaster.create({ title: 'Script updated from template', type: 'success', duration: 3000 });
|
|
159
|
+
onClose();
|
|
160
|
+
},
|
|
161
|
+
onError: (err: { message?: string }) => {
|
|
162
|
+
toaster.create({
|
|
163
|
+
title: 'Failed to update script',
|
|
164
|
+
description: err?.message || 'Unknown error',
|
|
165
|
+
type: 'error',
|
|
166
|
+
duration: 5000,
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<Dialog.Root
|
|
173
|
+
open={job != null}
|
|
174
|
+
onOpenChange={(details) => { if (!details.open) onClose(); }}
|
|
175
|
+
size="cover"
|
|
176
|
+
>
|
|
177
|
+
<Dialog.Backdrop />
|
|
178
|
+
<Dialog.Positioner>
|
|
179
|
+
<Dialog.Content maxW="95vw" maxH="95vh" overflow="hidden" display="flex" flexDirection="column">
|
|
180
|
+
<Dialog.Header>
|
|
181
|
+
<Dialog.Title>
|
|
182
|
+
Update "{job?.name}" from template {job?.source_template ? <Code>{job.source_template}</Code> : null}
|
|
183
|
+
</Dialog.Title>
|
|
184
|
+
<Dialog.CloseTrigger />
|
|
185
|
+
</Dialog.Header>
|
|
186
|
+
<Dialog.Body flex="1" overflow="hidden" display="flex" flexDirection="column" gap={3}>
|
|
187
|
+
{isLoading && <Spinner />}
|
|
188
|
+
{error && (
|
|
189
|
+
<Text color="red.500">{(error as { message?: string })?.message || 'Failed to load diff'}</Text>
|
|
190
|
+
)}
|
|
191
|
+
{diff && (
|
|
192
|
+
<>
|
|
193
|
+
<Text fontSize="sm" color="var(--color-text-muted)">
|
|
194
|
+
The template file has changed since this job's script was last loaded.
|
|
195
|
+
Review the new content below, then update to apply it.
|
|
196
|
+
</Text>
|
|
197
|
+
<Grid templateColumns="1fr 1fr" gap={4} flex="1" minH="0">
|
|
198
|
+
<Box display="flex" flexDirection="column" minH="0">
|
|
199
|
+
<Text fontSize="sm" fontWeight="medium" mb={1}>Current (running) script</Text>
|
|
200
|
+
<Box
|
|
201
|
+
as="pre"
|
|
202
|
+
flex="1"
|
|
203
|
+
minH="0"
|
|
204
|
+
fontSize="xs"
|
|
205
|
+
fontFamily="mono"
|
|
206
|
+
bg="var(--color-bg-page)"
|
|
207
|
+
p={3}
|
|
208
|
+
borderRadius="md"
|
|
209
|
+
borderWidth="1px"
|
|
210
|
+
borderColor="var(--color-border)"
|
|
211
|
+
overflow="auto"
|
|
212
|
+
whiteSpace="pre-wrap"
|
|
213
|
+
wordBreak="break-all"
|
|
214
|
+
>
|
|
215
|
+
{diff.current_script}
|
|
216
|
+
</Box>
|
|
217
|
+
</Box>
|
|
218
|
+
<Box display="flex" flexDirection="column" minH="0">
|
|
219
|
+
<Text fontSize="sm" fontWeight="medium" mb={1}>Latest template content</Text>
|
|
220
|
+
<Box
|
|
221
|
+
as="pre"
|
|
222
|
+
flex="1"
|
|
223
|
+
minH="0"
|
|
224
|
+
fontSize="xs"
|
|
225
|
+
fontFamily="mono"
|
|
226
|
+
bg="var(--color-bg-page)"
|
|
227
|
+
p={3}
|
|
228
|
+
borderRadius="md"
|
|
229
|
+
borderWidth="1px"
|
|
230
|
+
borderColor="green.500"
|
|
231
|
+
overflow="auto"
|
|
232
|
+
whiteSpace="pre-wrap"
|
|
233
|
+
wordBreak="break-all"
|
|
234
|
+
>
|
|
235
|
+
{diff.latest_script}
|
|
236
|
+
</Box>
|
|
237
|
+
</Box>
|
|
238
|
+
</Grid>
|
|
239
|
+
</>
|
|
240
|
+
)}
|
|
241
|
+
</Dialog.Body>
|
|
242
|
+
<Dialog.Footer>
|
|
243
|
+
<HStack gap={3}>
|
|
244
|
+
<Button variant="outline" onClick={onClose}>Cancel</Button>
|
|
245
|
+
<Button
|
|
246
|
+
colorPalette="blue"
|
|
247
|
+
onClick={() => syncMut.mutate()}
|
|
248
|
+
loading={syncMut.isPending}
|
|
249
|
+
disabled={!diff}
|
|
250
|
+
>
|
|
251
|
+
<LuRefreshCw />
|
|
252
|
+
Update script from template
|
|
253
|
+
</Button>
|
|
254
|
+
</HStack>
|
|
255
|
+
</Dialog.Footer>
|
|
256
|
+
</Dialog.Content>
|
|
257
|
+
</Dialog.Positioner>
|
|
258
|
+
</Dialog.Root>
|
|
259
|
+
);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// ─── Edit dialog ────────────────────────────────────────────────────
|
|
263
|
+
|
|
264
|
+
const EditScheduledJobDialog: React.FC<{
|
|
265
|
+
job: ScheduledJob | null;
|
|
266
|
+
onClose: () => void;
|
|
267
|
+
}> = ({ job, onClose }) => {
|
|
268
|
+
const queryClient = useQueryClient();
|
|
269
|
+
const [name, setName] = useState('');
|
|
270
|
+
const [cronPreset, setCronPreset] = useState('');
|
|
271
|
+
const [cronCustom, setCronCustom] = useState('');
|
|
272
|
+
const [jobNamePrefix, setJobNamePrefix] = useState('');
|
|
273
|
+
const [script, setScript] = useState('');
|
|
274
|
+
const [sourceTemplate, setSourceTemplate] = useState('');
|
|
275
|
+
const [sbatchArgsText, setSbatchArgsText] = useState('');
|
|
276
|
+
|
|
277
|
+
const { data: templates } = useQuery<string[]>({
|
|
278
|
+
queryKey: ['slurm-templates'],
|
|
279
|
+
queryFn: getSlurmTemplates,
|
|
280
|
+
enabled: job != null,
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
if (!job) return;
|
|
285
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect -- hydrates the edit dialog's form fields from whichever job record was selected for editing; every one of these fields is also independently mutated by the user typing in the form below, so this can't be replaced by a plain render-time derivation.
|
|
286
|
+
setName(job.name);
|
|
287
|
+
const preset = CRON_PRESETS.find(p => p.cron === job.cron_expression);
|
|
288
|
+
setCronPreset(preset ? job.cron_expression : '');
|
|
289
|
+
setCronCustom(job.cron_expression);
|
|
290
|
+
setJobNamePrefix(job.job_name_prefix || '');
|
|
291
|
+
setScript(job.script);
|
|
292
|
+
setSourceTemplate(job.source_template || '');
|
|
293
|
+
setSbatchArgsText((job.sbatch_args || []).join('\n'));
|
|
294
|
+
}, [job]);
|
|
295
|
+
|
|
296
|
+
const cron = cronPreset || cronCustom;
|
|
297
|
+
|
|
298
|
+
const saveMut = useMutation({
|
|
299
|
+
mutationFn: (payload: Partial<ScheduledJob>) => updateScheduledJob(job!._id, payload),
|
|
300
|
+
onSuccess: () => {
|
|
301
|
+
queryClient.invalidateQueries({ queryKey: ['scheduled-jobs'] });
|
|
302
|
+
toaster.create({ title: 'Scheduled job updated', type: 'success', duration: 3000 });
|
|
303
|
+
onClose();
|
|
304
|
+
},
|
|
305
|
+
onError: (error: { message?: string }) => {
|
|
306
|
+
toaster.create({
|
|
307
|
+
title: 'Failed to update scheduled job',
|
|
308
|
+
description: error?.message || 'Unknown error',
|
|
309
|
+
type: 'error',
|
|
310
|
+
duration: 5000,
|
|
311
|
+
});
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
const handleSave = () => {
|
|
316
|
+
if (!name.trim()) {
|
|
317
|
+
toaster.create({ title: 'Name is required', type: 'warning', duration: 3000 });
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (!cron.trim()) {
|
|
321
|
+
toaster.create({ title: 'Cron expression is required', type: 'warning', duration: 3000 });
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (!script.trim()) {
|
|
325
|
+
toaster.create({ title: 'Script is required', type: 'warning', duration: 3000 });
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const sbatch_args = sbatchArgsText
|
|
329
|
+
.split('\n')
|
|
330
|
+
.map((line) => line.trim())
|
|
331
|
+
.filter((line) => line.length > 0);
|
|
332
|
+
|
|
333
|
+
saveMut.mutate({
|
|
334
|
+
name: name.trim(),
|
|
335
|
+
cron_expression: cron.trim(),
|
|
336
|
+
job_name_prefix: jobNamePrefix.trim() || null,
|
|
337
|
+
script,
|
|
338
|
+
source_template: sourceTemplate || null,
|
|
339
|
+
sbatch_args,
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
return (
|
|
344
|
+
<Dialog.Root
|
|
345
|
+
open={job != null}
|
|
346
|
+
onOpenChange={(details) => { if (!details.open) onClose(); }}
|
|
347
|
+
size="cover"
|
|
348
|
+
>
|
|
349
|
+
<Dialog.Backdrop />
|
|
350
|
+
<Dialog.Positioner>
|
|
351
|
+
<Dialog.Content maxW="95vw" maxH="95vh" overflow="hidden" display="flex" flexDirection="column">
|
|
352
|
+
<Dialog.Header>
|
|
353
|
+
<Dialog.Title>Edit scheduled job</Dialog.Title>
|
|
354
|
+
<Dialog.CloseTrigger />
|
|
355
|
+
</Dialog.Header>
|
|
356
|
+
<Dialog.Body flex="1" overflow="hidden" display="flex" flexDirection="column" gap={4}>
|
|
357
|
+
<HStack gap={3} flexWrap="wrap" align="end">
|
|
358
|
+
<Field.Root flex="1" minW="180px">
|
|
359
|
+
<Field.Label>Name</Field.Label>
|
|
360
|
+
<Input value={name} onChange={(e) => setName(e.target.value)} />
|
|
361
|
+
</Field.Root>
|
|
362
|
+
<Field.Root w="200px">
|
|
363
|
+
<Field.Label>Schedule</Field.Label>
|
|
364
|
+
<NativeSelect.Root>
|
|
365
|
+
<NativeSelect.Field
|
|
366
|
+
value={cronPreset}
|
|
367
|
+
onChange={(e) => {
|
|
368
|
+
setCronPreset(e.target.value);
|
|
369
|
+
if (e.target.value) setCronCustom(e.target.value);
|
|
370
|
+
}}
|
|
371
|
+
>
|
|
372
|
+
<option value="">Custom</option>
|
|
373
|
+
{CRON_PRESETS.map((p) => (
|
|
374
|
+
<option key={p.cron} value={p.cron}>{p.label}</option>
|
|
375
|
+
))}
|
|
376
|
+
</NativeSelect.Field>
|
|
377
|
+
</NativeSelect.Root>
|
|
378
|
+
</Field.Root>
|
|
379
|
+
<Field.Root w="160px">
|
|
380
|
+
<Field.Label>Cron</Field.Label>
|
|
381
|
+
<Input
|
|
382
|
+
fontFamily="mono"
|
|
383
|
+
value={cronPreset || cronCustom}
|
|
384
|
+
onChange={(e) => {
|
|
385
|
+
setCronCustom(e.target.value);
|
|
386
|
+
setCronPreset('');
|
|
387
|
+
}}
|
|
388
|
+
placeholder="0 0 * * *"
|
|
389
|
+
/>
|
|
390
|
+
</Field.Root>
|
|
391
|
+
<Field.Root w="200px">
|
|
392
|
+
<Field.Label>Job name prefix</Field.Label>
|
|
393
|
+
<Input
|
|
394
|
+
value={jobNamePrefix}
|
|
395
|
+
onChange={(e) => setJobNamePrefix(e.target.value)}
|
|
396
|
+
placeholder="optional"
|
|
397
|
+
/>
|
|
398
|
+
</Field.Root>
|
|
399
|
+
<Field.Root w="220px">
|
|
400
|
+
<Field.Label>
|
|
401
|
+
Source template
|
|
402
|
+
{job?.template_missing && (
|
|
403
|
+
<Badge colorPalette="red" variant="subtle" ml={2}>missing</Badge>
|
|
404
|
+
)}
|
|
405
|
+
</Field.Label>
|
|
406
|
+
<NativeSelect.Root>
|
|
407
|
+
<NativeSelect.Field
|
|
408
|
+
value={sourceTemplate}
|
|
409
|
+
onChange={(e) => setSourceTemplate(e.target.value)}
|
|
410
|
+
>
|
|
411
|
+
<option value="">— none (custom script) —</option>
|
|
412
|
+
{sourceTemplate && !templates?.includes(sourceTemplate) && (
|
|
413
|
+
<option value={sourceTemplate}>{sourceTemplate} (missing)</option>
|
|
414
|
+
)}
|
|
415
|
+
{templates?.map((t) => (
|
|
416
|
+
<option key={t} value={t}>{t}</option>
|
|
417
|
+
))}
|
|
418
|
+
</NativeSelect.Field>
|
|
419
|
+
</NativeSelect.Root>
|
|
420
|
+
</Field.Root>
|
|
421
|
+
</HStack>
|
|
422
|
+
<Text fontSize="xs" color="var(--color-text-muted)" mt={-2}>
|
|
423
|
+
Setting or changing this only tracks which file the script came from
|
|
424
|
+
for drift detection -- it does not touch the script below.
|
|
425
|
+
</Text>
|
|
426
|
+
<Field.Root>
|
|
427
|
+
<Field.Label>
|
|
428
|
+
Sbatch arguments
|
|
429
|
+
<Text as="span" fontSize="xs" color="var(--color-text-muted)" fontWeight="normal" ml={2}>
|
|
430
|
+
one per line, e.g. -w cn-d004 or --gpus-per-task=8
|
|
431
|
+
</Text>
|
|
432
|
+
</Field.Label>
|
|
433
|
+
<Textarea
|
|
434
|
+
fontFamily="mono"
|
|
435
|
+
fontSize="sm"
|
|
436
|
+
rows={4}
|
|
437
|
+
value={sbatchArgsText}
|
|
438
|
+
onChange={(e) => setSbatchArgsText(e.target.value)}
|
|
439
|
+
placeholder={'--partition=long\n--nodes=1\n-w cn-d004'}
|
|
440
|
+
/>
|
|
441
|
+
</Field.Root>
|
|
442
|
+
<Box flex="1" minH="0" display="flex" flexDirection="column">
|
|
443
|
+
<Text fontSize="sm" fontWeight="medium" mb={1}>Script</Text>
|
|
444
|
+
<MonacoEditor value={script} onChange={setScript} height="100%" />
|
|
445
|
+
</Box>
|
|
446
|
+
</Dialog.Body>
|
|
447
|
+
<Dialog.Footer>
|
|
448
|
+
<HStack gap={3}>
|
|
449
|
+
<Button variant="outline" onClick={onClose}>Cancel</Button>
|
|
450
|
+
<Button colorPalette="blue" onClick={handleSave} loading={saveMut.isPending}>
|
|
451
|
+
Save
|
|
452
|
+
</Button>
|
|
453
|
+
</HStack>
|
|
454
|
+
</Dialog.Footer>
|
|
455
|
+
</Dialog.Content>
|
|
456
|
+
</Dialog.Positioner>
|
|
457
|
+
</Dialog.Root>
|
|
458
|
+
);
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
// ─── Main View ──────────────────────────────────────────────────────
|
|
462
|
+
|
|
463
|
+
export const ScheduledJobsView: React.FC = () => {
|
|
464
|
+
const queryClient = useQueryClient();
|
|
465
|
+
const [expandedJobId, setExpandedJobId] = useState<number | null>(null);
|
|
466
|
+
const [editingJob, setEditingJob] = useState<ScheduledJob | null>(null);
|
|
467
|
+
const [syncingJob, setSyncingJob] = useState<ScheduledJob | null>(null);
|
|
468
|
+
|
|
469
|
+
const { data: jobs, isLoading } = useQuery<ScheduledJob[]>({
|
|
470
|
+
queryKey: ['scheduled-jobs'],
|
|
471
|
+
queryFn: getScheduledJobs,
|
|
472
|
+
refetchInterval: 30_000,
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
const invalidate = useCallback(() => {
|
|
476
|
+
queryClient.invalidateQueries({ queryKey: ['scheduled-jobs'] });
|
|
477
|
+
}, [queryClient]);
|
|
478
|
+
|
|
479
|
+
const deleteMut = useMutation({
|
|
480
|
+
mutationFn: deleteScheduledJob,
|
|
481
|
+
onSuccess: invalidate,
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
const toggleMut = useMutation({
|
|
485
|
+
mutationFn: toggleScheduledJob,
|
|
486
|
+
onSuccess: invalidate,
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
const runNowMut = useMutation({
|
|
490
|
+
mutationFn: runScheduledJobNow,
|
|
491
|
+
onSuccess: (data) => {
|
|
492
|
+
invalidate();
|
|
493
|
+
queryClient.invalidateQueries({ queryKey: ['scheduled-runs'] });
|
|
494
|
+
toaster.create({
|
|
495
|
+
title: data.status === 'submitted' ? 'Job submitted' : 'Submission failed',
|
|
496
|
+
type: data.status === 'submitted' ? 'success' : 'error',
|
|
497
|
+
duration: 4000,
|
|
498
|
+
});
|
|
499
|
+
},
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
const toggleExpand = (id: number) => setExpandedJobId(prev => prev === id ? null : id);
|
|
503
|
+
|
|
504
|
+
return (
|
|
505
|
+
<Box p={6} bg="var(--color-bg-page)" h="100%" overflowY="auto">
|
|
506
|
+
<VStack align="stretch" gap={5} maxW="1400px" mx="auto">
|
|
507
|
+
<HStack justify="space-between" align="center">
|
|
508
|
+
<Heading size="lg" fontWeight="bold" color="var(--color-text)">Scheduled Slurm Jobs</Heading>
|
|
509
|
+
<Text fontSize="sm" color="var(--color-text-muted)">
|
|
510
|
+
Edit a job here, or create a new one from the <b>Submit Job</b> page.
|
|
511
|
+
</Text>
|
|
512
|
+
</HStack>
|
|
513
|
+
|
|
514
|
+
{isLoading && <Spinner />}
|
|
515
|
+
|
|
516
|
+
{jobs && jobs.length === 0 && (
|
|
517
|
+
<Text color="var(--color-text-muted)" fontStyle="italic">
|
|
518
|
+
No scheduled jobs yet. Go to Submit Job and use "Save as Scheduled Job" to create one.
|
|
519
|
+
</Text>
|
|
520
|
+
)}
|
|
521
|
+
|
|
522
|
+
{jobs && jobs.length > 0 && (
|
|
523
|
+
<Table.Root variant="outline" size="md">
|
|
524
|
+
<Table.Header>
|
|
525
|
+
<Table.Row>
|
|
526
|
+
<Table.ColumnHeader w="30px"></Table.ColumnHeader>
|
|
527
|
+
<Table.ColumnHeader>Name</Table.ColumnHeader>
|
|
528
|
+
<Table.ColumnHeader>Schedule</Table.ColumnHeader>
|
|
529
|
+
<Table.ColumnHeader>Cluster</Table.ColumnHeader>
|
|
530
|
+
<Table.ColumnHeader>Enabled</Table.ColumnHeader>
|
|
531
|
+
<Table.ColumnHeader>Last Run</Table.ColumnHeader>
|
|
532
|
+
<Table.ColumnHeader>Next Run</Table.ColumnHeader>
|
|
533
|
+
<Table.ColumnHeader textAlign="right">Actions</Table.ColumnHeader>
|
|
534
|
+
</Table.Row>
|
|
535
|
+
</Table.Header>
|
|
536
|
+
<Table.Body>
|
|
537
|
+
{jobs.map((job) => (
|
|
538
|
+
<React.Fragment key={job._id}>
|
|
539
|
+
<Table.Row
|
|
540
|
+
_hover={{ bg: 'var(--color-bg-hover)' }}
|
|
541
|
+
cursor="pointer"
|
|
542
|
+
onClick={() => toggleExpand(job._id)}
|
|
543
|
+
>
|
|
544
|
+
<Table.Cell>
|
|
545
|
+
{expandedJobId === job._id ? <LuChevronDown /> : <LuChevronRight />}
|
|
546
|
+
</Table.Cell>
|
|
547
|
+
<Table.Cell fontWeight="medium">
|
|
548
|
+
<HStack gap={2}>
|
|
549
|
+
<Text>{job.name}</Text>
|
|
550
|
+
{job.outdated && (
|
|
551
|
+
<Tooltip content={`Template "${job.source_template}" has changed since this job's script was loaded.`} showArrow>
|
|
552
|
+
<Badge colorPalette="orange" variant="solid">Outdated</Badge>
|
|
553
|
+
</Tooltip>
|
|
554
|
+
)}
|
|
555
|
+
{job.template_missing && (
|
|
556
|
+
<Tooltip content={`Source template "${job.source_template}" no longer exists.`} showArrow>
|
|
557
|
+
<Badge colorPalette="red" variant="subtle">Template missing</Badge>
|
|
558
|
+
</Tooltip>
|
|
559
|
+
)}
|
|
560
|
+
</HStack>
|
|
561
|
+
</Table.Cell>
|
|
562
|
+
<Table.Cell>
|
|
563
|
+
<VStack align="start" gap={0}>
|
|
564
|
+
<Text fontSize="sm">{cronHumanLabel(job.cron_expression)}</Text>
|
|
565
|
+
<Text fontSize="xs" color="var(--color-text-muted)" fontFamily="mono">{job.cron_expression}</Text>
|
|
566
|
+
</VStack>
|
|
567
|
+
</Table.Cell>
|
|
568
|
+
<Table.Cell><Badge variant="outline">{job.cluster}</Badge></Table.Cell>
|
|
569
|
+
<Table.Cell>
|
|
570
|
+
<Badge colorPalette={job.enabled ? 'green' : 'gray'} variant="subtle">
|
|
571
|
+
{job.enabled ? 'Enabled' : 'Disabled'}
|
|
572
|
+
</Badge>
|
|
573
|
+
</Table.Cell>
|
|
574
|
+
<Table.Cell fontSize="sm">{formatDate(job.last_run_time)}</Table.Cell>
|
|
575
|
+
<Table.Cell fontSize="sm">{job.enabled ? formatDate(job.next_run_time) : '—'}</Table.Cell>
|
|
576
|
+
<Table.Cell textAlign="right">
|
|
577
|
+
<HStack gap={1} justify="flex-end" onClick={e => e.stopPropagation()}>
|
|
578
|
+
{job.outdated && (
|
|
579
|
+
<Button
|
|
580
|
+
variant="ghost"
|
|
581
|
+
size="xs"
|
|
582
|
+
colorPalette="orange"
|
|
583
|
+
title="Update script from template"
|
|
584
|
+
onClick={() => setSyncingJob(job)}
|
|
585
|
+
>
|
|
586
|
+
<LuRefreshCw />
|
|
587
|
+
Update
|
|
588
|
+
</Button>
|
|
589
|
+
)}
|
|
590
|
+
<Button
|
|
591
|
+
variant="ghost"
|
|
592
|
+
size="xs"
|
|
593
|
+
title="Edit script"
|
|
594
|
+
onClick={() => setEditingJob(job)}
|
|
595
|
+
>
|
|
596
|
+
<LuPencil />
|
|
597
|
+
</Button>
|
|
598
|
+
<Button
|
|
599
|
+
variant="ghost"
|
|
600
|
+
size="xs"
|
|
601
|
+
title={job.enabled ? 'Disable' : 'Enable'}
|
|
602
|
+
onClick={() => toggleMut.mutate(job._id)}
|
|
603
|
+
loading={toggleMut.isPending}
|
|
604
|
+
>
|
|
605
|
+
<LuPower />
|
|
606
|
+
</Button>
|
|
607
|
+
<Button
|
|
608
|
+
variant="ghost"
|
|
609
|
+
size="xs"
|
|
610
|
+
title="Run now"
|
|
611
|
+
onClick={() => runNowMut.mutate(job._id)}
|
|
612
|
+
loading={runNowMut.isPending}
|
|
613
|
+
>
|
|
614
|
+
<LuPlay />
|
|
615
|
+
</Button>
|
|
616
|
+
<Button
|
|
617
|
+
variant="ghost"
|
|
618
|
+
size="xs"
|
|
619
|
+
colorPalette="red"
|
|
620
|
+
title="Delete"
|
|
621
|
+
onClick={() => { if (window.confirm(`Delete "${job.name}"?`)) deleteMut.mutate(job._id); }}
|
|
622
|
+
loading={deleteMut.isPending}
|
|
623
|
+
>
|
|
624
|
+
<LuTrash2 />
|
|
625
|
+
</Button>
|
|
626
|
+
</HStack>
|
|
627
|
+
</Table.Cell>
|
|
628
|
+
</Table.Row>
|
|
629
|
+
{expandedJobId === job._id && (
|
|
630
|
+
<Table.Row>
|
|
631
|
+
<Table.Cell colSpan={8} p={4} bg="var(--color-bg-header)">
|
|
632
|
+
<Grid templateColumns="1fr 1fr" gap={4}>
|
|
633
|
+
{/* Left: Job Config */}
|
|
634
|
+
<Card.Root variant="outline" p={3} bg="var(--color-bg-card)">
|
|
635
|
+
<VStack align="stretch" gap={3}>
|
|
636
|
+
<Heading size="sm">Configuration</Heading>
|
|
637
|
+
<HStack gap={6} flexWrap="wrap">
|
|
638
|
+
<VStack align="start" gap={0}>
|
|
639
|
+
<Text fontSize="xs" color="var(--color-text-muted)">Cluster</Text>
|
|
640
|
+
<Text fontSize="sm" fontWeight="medium">{job.cluster}</Text>
|
|
641
|
+
</VStack>
|
|
642
|
+
<VStack align="start" gap={0}>
|
|
643
|
+
<Text fontSize="xs" color="var(--color-text-muted)">Cron</Text>
|
|
644
|
+
<Code fontSize="sm">{job.cron_expression}</Code>
|
|
645
|
+
</VStack>
|
|
646
|
+
{job.job_name_prefix && (
|
|
647
|
+
<VStack align="start" gap={0}>
|
|
648
|
+
<Text fontSize="xs" color="var(--color-text-muted)">Job Name Prefix</Text>
|
|
649
|
+
<Text fontSize="sm" fontWeight="medium">{job.job_name_prefix}</Text>
|
|
650
|
+
</VStack>
|
|
651
|
+
)}
|
|
652
|
+
<VStack align="start" gap={0}>
|
|
653
|
+
<Text fontSize="xs" color="var(--color-text-muted)">Source Template</Text>
|
|
654
|
+
{job.source_template ? (
|
|
655
|
+
<Code fontSize="sm">{job.source_template}</Code>
|
|
656
|
+
) : (
|
|
657
|
+
<Text fontSize="sm" color="var(--color-text-muted)" fontStyle="italic">
|
|
658
|
+
custom (not tracked)
|
|
659
|
+
</Text>
|
|
660
|
+
)}
|
|
661
|
+
</VStack>
|
|
662
|
+
<VStack align="start" gap={0}>
|
|
663
|
+
<Text fontSize="xs" color="var(--color-text-muted)">Created</Text>
|
|
664
|
+
<Text fontSize="sm">{formatDate(job.created_time)}</Text>
|
|
665
|
+
</VStack>
|
|
666
|
+
<VStack align="start" gap={0}>
|
|
667
|
+
<Text fontSize="xs" color="var(--color-text-muted)">Modified</Text>
|
|
668
|
+
<Text fontSize="sm">{formatDate(job.modified_time)}</Text>
|
|
669
|
+
</VStack>
|
|
670
|
+
</HStack>
|
|
671
|
+
{job.sbatch_args && job.sbatch_args.length > 0 && (
|
|
672
|
+
<VStack align="start" gap={1}>
|
|
673
|
+
<Text fontSize="xs" color="var(--color-text-muted)">Sbatch Arguments</Text>
|
|
674
|
+
<HStack gap={1} flexWrap="wrap">
|
|
675
|
+
{job.sbatch_args.map((arg, i) => (
|
|
676
|
+
<Badge key={i} variant="outline" fontFamily="mono" fontSize="xs">{arg}</Badge>
|
|
677
|
+
))}
|
|
678
|
+
</HStack>
|
|
679
|
+
</VStack>
|
|
680
|
+
)}
|
|
681
|
+
<VStack align="start" gap={1}>
|
|
682
|
+
<HStack justify="space-between" w="100%">
|
|
683
|
+
<Text fontSize="xs" color="var(--color-text-muted)">Script</Text>
|
|
684
|
+
<Button
|
|
685
|
+
variant="ghost"
|
|
686
|
+
size="xs"
|
|
687
|
+
onClick={() => setEditingJob(job)}
|
|
688
|
+
>
|
|
689
|
+
<LuPencil />
|
|
690
|
+
Edit
|
|
691
|
+
</Button>
|
|
692
|
+
</HStack>
|
|
693
|
+
<Box
|
|
694
|
+
as="pre"
|
|
695
|
+
fontSize="xs"
|
|
696
|
+
fontFamily="mono"
|
|
697
|
+
bg="var(--color-bg-page)"
|
|
698
|
+
p={3}
|
|
699
|
+
borderRadius="md"
|
|
700
|
+
borderWidth="1px"
|
|
701
|
+
borderColor="var(--color-border)"
|
|
702
|
+
w="100%"
|
|
703
|
+
maxH="300px"
|
|
704
|
+
overflowY="auto"
|
|
705
|
+
whiteSpace="pre-wrap"
|
|
706
|
+
wordBreak="break-all"
|
|
707
|
+
>
|
|
708
|
+
{job.script}
|
|
709
|
+
</Box>
|
|
710
|
+
</VStack>
|
|
711
|
+
</VStack>
|
|
712
|
+
</Card.Root>
|
|
713
|
+
|
|
714
|
+
{/* Right: Run History */}
|
|
715
|
+
<Card.Root variant="outline" p={3} bg="var(--color-bg-card)">
|
|
716
|
+
<VStack align="stretch" gap={3}>
|
|
717
|
+
<Heading size="sm">Run History</Heading>
|
|
718
|
+
<RunHistory jobId={job._id} />
|
|
719
|
+
</VStack>
|
|
720
|
+
</Card.Root>
|
|
721
|
+
</Grid>
|
|
722
|
+
</Table.Cell>
|
|
723
|
+
</Table.Row>
|
|
724
|
+
)}
|
|
725
|
+
</React.Fragment>
|
|
726
|
+
))}
|
|
727
|
+
</Table.Body>
|
|
728
|
+
</Table.Root>
|
|
729
|
+
)}
|
|
730
|
+
</VStack>
|
|
731
|
+
<EditScheduledJobDialog job={editingJob} onClose={() => setEditingJob(null)} />
|
|
732
|
+
<TemplateSyncDialog job={syncingJob} onClose={() => setSyncingJob(null)} />
|
|
733
|
+
</Box>
|
|
734
|
+
);
|
|
735
|
+
};
|