fix(tasks): preserve timestamps when listing (#1198)
Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
51356b4195
commit
1f6cea50ed
@@ -270,6 +270,7 @@ const normalizeTaskForStorage = (value, options) => {
|
|||||||
createId,
|
createId,
|
||||||
existingTask,
|
existingTask,
|
||||||
allowCreate,
|
allowCreate,
|
||||||
|
refreshUpdatedAt = true,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
if (!value || typeof value !== 'object') {
|
if (!value || typeof value !== 'object') {
|
||||||
@@ -307,7 +308,7 @@ const normalizeTaskForStorage = (value, options) => {
|
|||||||
const state = {
|
const state = {
|
||||||
...baseState,
|
...baseState,
|
||||||
createdAt: existingTask?.state?.createdAt ?? baseState.createdAt ?? nowMs,
|
createdAt: existingTask?.state?.createdAt ?? baseState.createdAt ?? nowMs,
|
||||||
updatedAt: nowMs,
|
updatedAt: refreshUpdatedAt ? nowMs : baseState.updatedAt ?? nowMs,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -386,6 +387,7 @@ export const createProjectConfigRuntime = (deps) => {
|
|||||||
createId: taskIDFactory,
|
createId: taskIDFactory,
|
||||||
existingTask: null,
|
existingTask: null,
|
||||||
allowCreate: true,
|
allowCreate: true,
|
||||||
|
refreshUpdatedAt: false,
|
||||||
});
|
});
|
||||||
scheduledTasks.push(normalized);
|
scheduledTasks.push(normalized);
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -114,6 +114,37 @@ describe('project-config runtime', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('preserves scheduled task state timestamps when listing tasks', async () => {
|
||||||
|
const { runtime, cleanup } = await createRuntime();
|
||||||
|
try {
|
||||||
|
const projectID = 'timestamp_preserve';
|
||||||
|
const filePath = path.join(runtime.resolveProjectConfigPath(projectID));
|
||||||
|
await writeFile(
|
||||||
|
filePath,
|
||||||
|
JSON.stringify({
|
||||||
|
scheduledTasks: [{
|
||||||
|
id: 'task-existing',
|
||||||
|
name: 'nightly',
|
||||||
|
enabled: true,
|
||||||
|
schedule: { kind: 'daily', times: ['09:00'], timezone: 'UTC' },
|
||||||
|
execution: { prompt: 'run', providerID: 'openai', modelID: 'gpt-4.1' },
|
||||||
|
state: { createdAt: 10, updatedAt: 20, lastStatus: 'idle' },
|
||||||
|
}],
|
||||||
|
}, null, 2),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
|
||||||
|
const first = await runtime.listScheduledTasks(projectID);
|
||||||
|
const second = await runtime.listScheduledTasks(projectID);
|
||||||
|
|
||||||
|
expect(first[0].state.createdAt).toBe(10);
|
||||||
|
expect(first[0].state.updatedAt).toBe(20);
|
||||||
|
expect(second[0].state.updatedAt).toBe(20);
|
||||||
|
} finally {
|
||||||
|
await cleanup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('accepts one-time schedule with date and time', async () => {
|
it('accepts one-time schedule with date and time', async () => {
|
||||||
const { runtime, cleanup } = await createRuntime();
|
const { runtime, cleanup } = await createRuntime();
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user