Show the restart countdown for the whole scheduled window.
Players see the update toast as soon as a midnight restart is planned, not only in the last three hours.
@@ -1,14 +1,13 @@
1
1
import {
2
2
RESTART_WARN_BEFORE_MS,
3
3
DEFAULT_DEPLOY_CHECK_MS,
4
nextLocalMidnightMs,
5
isInRestartWarningWindow
4
nextLocalMidnightMs
6
5
} from "../../../shared/deploy/schedule.js";
7
6
import { checkGitRemoteAhead } from "./gitRemote.js";
8
7
9
8
/**
10
9
* Schedules a graceful midnight restart only when origin/<branch> is ahead of HEAD.
11
* Three hours before midnight, clients enter the permanent countdown toast window.
10
* Clients see a permanent countdown toast for the whole time a restart is scheduled.
12
11
*/
13
12
export class DeployScheduler
14
13
{
@@ -86,9 +85,7 @@ export class DeployScheduler
86
85
{
87
86
const now = this.now();
88
87
const scheduled = this.scheduledAt != null;
89
const warning = scheduled && (
90
this.warningActive || isInRestartWarningWindow(now, this.scheduledAt, this.warnBeforeMs)
91
);
88
const warning = scheduled && now < this.scheduledAt;
92
89
return {
93
90
scheduled,
94
91
scheduledAt: this.scheduledAt,
@@ -129,16 +126,10 @@ export class DeployScheduler
129
126
if (!this.enabled || this.restartFired || this.scheduledAt == null)
130
127
{ return; }
131
128
const now = this.now();
132
const warning = isInRestartWarningWindow(now, this.scheduledAt, this.warnBeforeMs)
133
|| now >= this.scheduledAt;
134
if (warning !== this.warningActive)
135
{
136
this.warningActive = warning;
137
this.onStatusChange(this.status());
138
}
139
129
if (now >= this.scheduledAt)
140
130
{
141
131
this.restartFired = true;
132
this.warningActive = true;
142
133
this.onRestartDue(this.status());
143
134
}
144
135
}
@@ -148,7 +139,7 @@ export class DeployScheduler
148
139
{
149
140
this.scheduledAt = scheduledAt;
150
141
this.reasons = [...reasons];
151
this.warningActive = isInRestartWarningWindow(this.now(), scheduledAt, this.warnBeforeMs);
142
this.warningActive = scheduledAt != null && this.now() < scheduledAt;
152
143
this.onStatusChange(this.status());
153
144
}
154
145
@@ -158,7 +149,7 @@ export class DeployScheduler
158
149
{ return; }
159
150
this.scheduledAt = nextLocalMidnightMs(this.now());
160
151
this.reasons = ["code-update"];
161
this.warningActive = isInRestartWarningWindow(this.now(), this.scheduledAt, this.warnBeforeMs);
152
this.warningActive = this.now() < this.scheduledAt;
162
153
console.log(
163
154
`[deploy] origin/${this.branch} is ahead; restart scheduled for ${new Date(this.scheduledAt).toString()}`
164
155
);
@@ -1,14 +1,13 @@1
import {1
import {2
RESTART_WARN_BEFORE_MS,2
RESTART_WARN_BEFORE_MS,3
DEFAULT_DEPLOY_CHECK_MS,3
DEFAULT_DEPLOY_CHECK_MS,4
nextLocalMidnightMs,4
nextLocalMidnightMs5
isInRestartWarningWindow6
} from "../../../shared/deploy/schedule.js";5
} from "../../../shared/deploy/schedule.js";7
import { checkGitRemoteAhead } from "./gitRemote.js";6
import { checkGitRemoteAhead } from "./gitRemote.js";8
7
9
/**8
/**10
* Schedules a graceful midnight restart only when origin/<branch> is ahead of HEAD.9
* Schedules a graceful midnight restart only when origin/<branch> is ahead of HEAD.11
* Three hours before midnight, clients enter the permanent countdown toast window.10
* Clients see a permanent countdown toast for the whole time a restart is scheduled.12
*/11
*/13
export class DeployScheduler12
export class DeployScheduler14
{13
{@@ -86,9 +85,7 @@ export class DeployScheduler86
{85
{87
const now = this.now();86
const now = this.now();88
const scheduled = this.scheduledAt != null;87
const scheduled = this.scheduledAt != null;89
const warning = scheduled && (88
const warning = scheduled && now < this.scheduledAt;90
this.warningActive || isInRestartWarningWindow(now, this.scheduledAt, this.warnBeforeMs)91
);92
return {89
return {93
scheduled,90
scheduled,94
scheduledAt: this.scheduledAt,91
scheduledAt: this.scheduledAt,@@ -129,16 +126,10 @@ export class DeployScheduler129
if (!this.enabled || this.restartFired || this.scheduledAt == null)126
if (!this.enabled || this.restartFired || this.scheduledAt == null)130
{ return; }127
{ return; }131
const now = this.now();128
const now = this.now();132
const warning = isInRestartWarningWindow(now, this.scheduledAt, this.warnBeforeMs)133
|| now >= this.scheduledAt;134
if (warning !== this.warningActive)135
{136
this.warningActive = warning;137
this.onStatusChange(this.status());138
}139
if (now >= this.scheduledAt)129
if (now >= this.scheduledAt)140
{130
{141
this.restartFired = true;131
this.restartFired = true;132
this.warningActive = true;142
this.onRestartDue(this.status());133
this.onRestartDue(this.status());143
}134
}144
}135
}@@ -148,7 +139,7 @@ export class DeployScheduler148
{139
{149
this.scheduledAt = scheduledAt;140
this.scheduledAt = scheduledAt;150
this.reasons = [...reasons];141
this.reasons = [...reasons];151
this.warningActive = isInRestartWarningWindow(this.now(), scheduledAt, this.warnBeforeMs);142
this.warningActive = scheduledAt != null && this.now() < scheduledAt;152
this.onStatusChange(this.status());143
this.onStatusChange(this.status());153
}144
}154
145
@@ -158,7 +149,7 @@ export class DeployScheduler158
{ return; }149
{ return; }159
this.scheduledAt = nextLocalMidnightMs(this.now());150
this.scheduledAt = nextLocalMidnightMs(this.now());160
this.reasons = ["code-update"];151
this.reasons = ["code-update"];161
this.warningActive = isInRestartWarningWindow(this.now(), this.scheduledAt, this.warnBeforeMs);152
this.warningActive = this.now() < this.scheduledAt;162
console.log(153
console.log(163
`[deploy] origin/${this.branch} is ahead; restart scheduled for ${new Date(this.scheduledAt).toString()}`154
`[deploy] origin/${this.branch} is ahead; restart scheduled for ${new Date(this.scheduledAt).toString()}`164
);155
);@@ -31,12 +31,13 @@ test("nextLocalMidnightMs is the following calendar midnight", () =>
31
31
assert.equal(d.getMinutes(), 0);
32
32
});
33
33
34
test("warning window opens three hours before midnight", () =>
34
test("warning window stays open for the whole scheduled period", () =>
35
35
{
36
36
const scheduledAt = new Date(2026, 7, 28, 0, 0, 0, 0).getTime();
37
assert.equal(restartWarningStartsAt(scheduledAt), scheduledAt - RESTART_WARN_BEFORE_MS);
37
assert.equal(restartWarningStartsAt(scheduledAt), 0);
38
38
assert.equal(isInRestartWarningWindow(scheduledAt - RESTART_WARN_BEFORE_MS, scheduledAt), true);
39
assert.equal(isInRestartWarningWindow(scheduledAt - RESTART_WARN_BEFORE_MS - 1, scheduledAt), false);
39
assert.equal(isInRestartWarningWindow(scheduledAt - RESTART_WARN_BEFORE_MS - 1, scheduledAt), true);
40
assert.equal(isInRestartWarningWindow(scheduledAt - 12 * 60 * 60 * 1000, scheduledAt), true);
40
41
assert.equal(isInRestartWarningWindow(scheduledAt, scheduledAt), false);
41
42
});
42
43
@@ -89,7 +90,7 @@ test("DeployScheduler schedules only when remote is ahead", async () =>
89
90
await scheduler.poll();
90
91
assert.equal(scheduler.status().scheduled, true);
91
92
assert.equal(scheduler.status().scheduledAt, nextLocalMidnightMs(now));
92
assert.equal(scheduler.status().warning, false);
93
assert.equal(scheduler.status().warning, true);
93
94
94
95
now = scheduler.status().scheduledAt - RESTART_WARN_BEFORE_MS;
95
96
scheduler.tick();
@@ -31,12 +31,13 @@ test("nextLocalMidnightMs is the following calendar midnight", () =>31
assert.equal(d.getMinutes(), 0);31
assert.equal(d.getMinutes(), 0);32
});32
});33
33
34
test("warning window opens three hours before midnight", () =>34
test("warning window stays open for the whole scheduled period", () =>35
{35
{36
const scheduledAt = new Date(2026, 7, 28, 0, 0, 0, 0).getTime();36
const scheduledAt = new Date(2026, 7, 28, 0, 0, 0, 0).getTime();37
assert.equal(restartWarningStartsAt(scheduledAt), scheduledAt - RESTART_WARN_BEFORE_MS);37
assert.equal(restartWarningStartsAt(scheduledAt), 0);38
assert.equal(isInRestartWarningWindow(scheduledAt - RESTART_WARN_BEFORE_MS, scheduledAt), true);38
assert.equal(isInRestartWarningWindow(scheduledAt - RESTART_WARN_BEFORE_MS, scheduledAt), true);39
assert.equal(isInRestartWarningWindow(scheduledAt - RESTART_WARN_BEFORE_MS - 1, scheduledAt), false);39
assert.equal(isInRestartWarningWindow(scheduledAt - RESTART_WARN_BEFORE_MS - 1, scheduledAt), true);40
assert.equal(isInRestartWarningWindow(scheduledAt - 12 * 60 * 60 * 1000, scheduledAt), true);40
assert.equal(isInRestartWarningWindow(scheduledAt, scheduledAt), false);41
assert.equal(isInRestartWarningWindow(scheduledAt, scheduledAt), false);41
});42
});42
43
@@ -89,7 +90,7 @@ test("DeployScheduler schedules only when remote is ahead", async () =>89
await scheduler.poll();90
await scheduler.poll();90
assert.equal(scheduler.status().scheduled, true);91
assert.equal(scheduler.status().scheduled, true);91
assert.equal(scheduler.status().scheduledAt, nextLocalMidnightMs(now));92
assert.equal(scheduler.status().scheduledAt, nextLocalMidnightMs(now));92
assert.equal(scheduler.status().warning, false);93
assert.equal(scheduler.status().warning, true);93
94
94
now = scheduler.status().scheduledAt - RESTART_WARN_BEFORE_MS;95
now = scheduler.status().scheduledAt - RESTART_WARN_BEFORE_MS;95
scheduler.tick();96
scheduler.tick();