storing last run in database

This commit is contained in:
orangecoding
2026-06-09 16:52:37 +02:00
parent 6bef907416
commit bc9c56a224
9 changed files with 287 additions and 85 deletions

View File

@@ -29,6 +29,7 @@ describe('services/jobs/jobExecutionService', () => {
vi.doMock(jobStoragePath, () => ({
getJob: (id) => state.jobsById[id] || null,
getJobs: () => state.jobsList.slice(),
updateJobLastRunAt: (id, timestamp) => calls.lastRunUpdates.push({ id, timestamp }),
}));
vi.doMock(userStoragePath, () => ({
getUsers: () => state.users.slice(),
@@ -65,7 +66,7 @@ describe('services/jobs/jobExecutionService', () => {
beforeEach(() => {
bus = new EventEmitter();
calls = { sent: [], markRunning: [] };
calls = { sent: [], markRunning: [], lastRunUpdates: [] };
state = {
jobsById: {},
jobsList: [],
@@ -119,4 +120,23 @@ describe('services/jobs/jobExecutionService', () => {
await new Promise((r) => setTimeout(r, 0));
expect(new Set(calls.markRunning)).toEqual(new Set(['j1', 'j2']));
});
it('persists last_run_at when a job is executed', async () => {
state.jobsById['j1'] = { id: 'j1', enabled: true, userId: 'u1', provider: [] };
state.jobsList = [state.jobsById['j1']];
state.users = [{ id: 'u1', isAdmin: false }];
await initService();
const before = Date.now();
bus.emit('jobs:runOne', { jobId: 'j1' });
await new Promise((r) => setTimeout(r, 0));
const after = Date.now();
expect(calls.lastRunUpdates.length).toBe(1);
const [update] = calls.lastRunUpdates;
expect(update.id).toBe('j1');
expect(update.timestamp).toBeGreaterThanOrEqual(before);
expect(update.timestamp).toBeLessThanOrEqual(after);
});
});