-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsys-report-schedule.object.ts
More file actions
178 lines (158 loc) · 4.73 KB
/
Copy pathsys-report-schedule.object.ts
File metadata and controls
178 lines (158 loc) · 4.73 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { ObjectSchema, Field } from '@objectstack/spec/data';
/**
* sys_report_schedule — Recurring Report Delivery
*
* Joins a `sys_saved_report` to an interval and a recipient list so
* the reports plugin can deliver "daily pipeline digest" / "weekly
* lead summary" without a separate workflow.
*
* Scheduling: `interval_minutes` (1440 = daily, 10080 = weekly) or a
* `cron_expression`. When a `cron_expression` is set it wins over
* `interval_minutes` and is evaluated in `timezone` (default UTC) via
* croner — so "every weekday 09:00 local" is expressible. `next_run_at`
* is computed from whichever applies.
*
* Delivery: when the master dispatch job ticks (every minute by
* default), every schedule with `next_run_at <= now` is loaded,
* its report is executed, the result is rendered into the report's
* `format`, and the rendered body is emailed to each address in
* `recipients`. `next_run_at` is then advanced by `interval_minutes`.
*
* Conventions:
* - `recipients` is a comma-separated list of RFC-5322 addresses to
* keep the schema driver-agnostic. The reports plugin splits and
* trims before handing the list to IEmailService.
* - `active=false` disables the schedule without losing its history.
*
* @namespace sys
*/
export const SysReportSchedule = ObjectSchema.create({
name: 'sys_report_schedule',
label: 'Report Schedule',
pluralLabel: 'Report Schedules',
icon: 'clock',
isSystem: true,
managedBy: 'platform',
description: 'Recurring delivery of a sys_saved_report via email',
titleFormat: '{report_id} → {recipients}',
compactLayout: ['report_id', 'recipients', 'interval_minutes', 'active', 'next_run_at'],
fields: {
id: Field.text({
label: 'Schedule ID',
required: true,
readonly: true,
group: 'System',
}),
report_id: Field.lookup('sys_saved_report', {
label: 'Report',
required: true,
group: 'Schedule',
}),
name: Field.text({
label: 'Name',
required: false,
maxLength: 200,
description: 'Optional label for the digest — used in the email subject',
group: 'Schedule',
}),
interval_minutes: Field.number({
label: 'Interval (minutes)',
required: false,
defaultValue: 1440,
description: 'How often to send (1440 = daily, 10080 = weekly)',
group: 'Schedule',
}),
cron_expression: Field.text({
label: 'Cron Expression',
required: false,
maxLength: 100,
description: 'Optional 5/6-field cron — overrides interval_minutes when present',
group: 'Schedule',
}),
timezone: Field.text({
label: 'Timezone',
required: false,
maxLength: 64,
defaultValue: 'UTC',
group: 'Schedule',
}),
active: Field.boolean({
label: 'Active',
required: true,
defaultValue: true,
group: 'Schedule',
}),
recipients: Field.text({
label: 'Recipients',
required: true,
maxLength: 4000,
description: 'Comma-separated email addresses',
group: 'Delivery',
}),
format: Field.select(
['csv', 'html_table'],
{
label: 'Format',
required: false,
defaultValue: 'html_table',
description: 'Render format — csv is attached, html_table is inlined',
group: 'Delivery',
},
),
subject_template: Field.text({
label: 'Subject Template',
required: false,
maxLength: 200,
description: 'Email subject; {{name}} / {{date}} / {{rows}} are substituted',
group: 'Delivery',
}),
owner_id: Field.lookup('sys_user', {
label: 'Owner',
required: false,
group: 'Provenance',
}),
next_run_at: Field.datetime({
label: 'Next Run',
required: false,
description: 'Dispatcher loads schedules where next_run_at <= now',
group: 'State',
}),
last_sent_at: Field.datetime({
label: 'Last Sent',
required: false,
group: 'State',
}),
last_status: Field.select(
['ok', 'failed', 'skipped'],
{
label: 'Last Status',
required: false,
group: 'State',
},
),
last_error: Field.textarea({
label: 'Last Error',
required: false,
group: 'State',
}),
created_at: Field.datetime({
label: 'Created At',
required: true,
defaultValue: 'NOW()',
readonly: true,
group: 'System',
}),
updated_at: Field.datetime({
label: 'Updated At',
required: false,
group: 'System',
}),
},
indexes: [
// Hot path for the dispatch loop.
{ fields: ['active', 'next_run_at'] },
{ fields: ['report_id'] },
{ fields: ['owner_id'] },
],
});