MCPcopy Index your code
hub / github.com/ether/etherpad / decideSchedule

Function decideSchedule

src/node/updater/Scheduler.ts:58–108  ·  view source on GitHub ↗
(input: DecideScheduleInput)

Source from the content-addressed store, hash-verified

56 * email when `adminEmail` is set and `email.graceStartTag !== latest.tag`.
57 */
58export const decideSchedule = (input: DecideScheduleInput): SchedulerDecision => {
59 const {
60 state, now, policy, latest, current, preApplyGraceMinutes, adminEmail,
61 maintenanceWindow,
62 } = input;
63 const status = state.execution.status;
64
65 if (!latest) return {action: 'nothing'};
66
67 if (!policy.canAuto) {
68 if (status === 'scheduled') return {action: 'cancel-schedule', reason: 'policy-denied'};
69 return {action: 'nothing'};
70 }
71
72 if (IN_FLIGHT.has(status) || TERMINAL.has(status)) return {action: 'nothing'};
73
74 if (status === 'scheduled'
75 && (state.execution as {targetTag: string}).targetTag === latest.tag) {
76 return {action: 'nothing'};
77 }
78
79 const graceMs = clampGrace(preApplyGraceMinutes) * 60 * 1000;
80 let scheduledForDate = new Date(now.getTime() + graceMs);
81 // Tier 4: snap forward to the next opening if grace lands outside the window.
82 if (policy.canAutonomous && maintenanceWindow) {
83 if (!inWindow(scheduledForDate, maintenanceWindow)) {
84 scheduledForDate = nextWindowStart(scheduledForDate, maintenanceWindow);
85 }
86 }
87 const scheduledFor = scheduledForDate.toISOString();
88 const newExecution = {
89 status: 'scheduled' as const,
90 targetTag: latest.tag,
91 scheduledFor,
92 startedAt: now.toISOString(),
93 };
94
95 const emails: PlannedEmail[] = [];
96 const newEmailState: EmailSendLog = {...state.email};
97 if (adminEmail && state.email.graceStartTag !== latest.tag) {
98 emails.push({
99 kind: 'grace-start',
100 subject: `[Etherpad] Auto-update scheduled for ${latest.version}`,
101 body: `Etherpad will auto-update to ${latest.tag} at ${scheduledFor}. ` +
102 `Your version is ${current}. To cancel, visit /admin/update.`,
103 });
104 newEmailState.graceStartTag = latest.tag;
105 }
106
107 return {action: 'schedule', newExecution, emails, newEmailState};
108};
109
110export type TriggerApplyDecision =
111 | {action: 'fire'}

Callers 4

Scheduler.test.tsFile · 0.90
performCheckFunction · 0.90

Calls 4

inWindowFunction · 0.90
nextWindowStartFunction · 0.90
clampGraceFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected