-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheduler-job.entity.ts
More file actions
50 lines (48 loc) · 1.83 KB
/
Copy pathscheduler-job.entity.ts
File metadata and controls
50 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { defineEntity, type InferEntity } from '@mikro-orm/core';
import { SchedulerJobRepository } from '../repositories/scheduler-job.repository.ts';
import { BaseSchema } from './base.entity.ts';
export const SchedulerJobEntitySchema = defineEntity({
name: 'SchedulerJobEntity',
tableName: 'scheduled_jobs',
comment: 'Persistent scheduler jobs and leases',
extends: BaseSchema,
repository: () => SchedulerJobRepository,
properties: (p) => ({
id: p.string().primary().comment('Stable scheduler job identifier'),
name: p.string().comment('Human-readable scheduler job name'),
enabled: p
.boolean()
.comment('Whether the scheduler job is enabled')
.default(true),
cron: p.string().comment('Cron expression for the job schedule'),
nextRunAt: p.datetime().comment('Next scheduled run timestamp').nullable(),
lastRunAt: p.datetime().comment('Last run start timestamp').nullable(),
lastSuccessAt: p
.datetime()
.comment('Last successful completion timestamp')
.nullable(),
lastErrorAt: p
.datetime()
.comment('Last failed completion timestamp')
.nullable(),
lastError: p.text().comment('Last failure message').nullable(),
lockedBy: p
.string()
.comment('Scheduler instance holding the lease')
.nullable(),
lockedUntil: p.datetime().comment('Lease expiration timestamp').nullable(),
runCount: p.integer().comment('Total run attempts').default(0),
failureCount: p.integer().comment('Total failed run attempts').default(0),
}),
indexes: [
{
name: 'scheduled_jobs_enabled_next_run_at_idx',
properties: ['enabled', 'nextRunAt'],
},
{
name: 'scheduled_jobs_locked_until_idx',
properties: ['lockedUntil'],
},
],
});
export type ISchedulerJobEntity = InferEntity<typeof SchedulerJobEntitySchema>;