Skip to content

Commit 3fa1dd3

Browse files
committed
Make restart a condition of allowing upgrades
1 parent abced10 commit 3fa1dd3

File tree

3 files changed

+46
-56
lines changed

3 files changed

+46
-56
lines changed

forge/ee/lib/autoUpdateStacks/tasks/upgrade-stack.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,30 @@ module.exports = {
1818
const projectList = await app.db.models.ProjectSettings.getProjectsToUpgrade(hour, day)
1919
if (projectList) {
2020
for (const project of projectList) {
21-
if (project.value.restartOnly) { // this might need to be a separate flag to make the query work
21+
// we should probably rate limit this to not restart lots of projects at once
22+
if (project.Project.ProjectStack.replacedBy) {
23+
// need to add audit logging
24+
try {
25+
const newStack = await app.db.models.ProjectStack.byId(project.Project.ProjectStack.replacedBy)
26+
app.log.info(`Updating project ${project.Project.id} to stack: '${newStack.hashid}'`)
27+
28+
const suspendOptions = {
29+
skipBilling: true
30+
}
31+
32+
app.db.controllers.Project.setInflightState(project.Project, 'starting')
33+
const result = await suspendProject(project.Project, suspendOptions)
34+
35+
await project.Project.setProjectStack(newStack)
36+
await project.Project.save()
37+
38+
await app.auditLog.Project.project.stack.changed(null, null, project.Project, newStack)
39+
40+
await unSuspendProject(project.Project, result.resumeProject, result.targetState)
41+
} catch (err) {
42+
app.log.info(`Problem updating project ${project.Project.id} - ${err.toString()}`)
43+
}
44+
} else if (project.value.restart) {
2245
try {
2346
app.log.info(`Restarting project ${project.Project.id} as scheduled`)
2447
await app.db.controllers.Project.setInflightState(project.Project, 'restarting')
@@ -30,31 +53,6 @@ module.exports = {
3053
} catch (err) {
3154
app.log.info(`Problem restarting project ${project.Project.id} - ${err.toString()}`)
3255
}
33-
} else {
34-
// we should probably rate limit this to not restart lots of projects at once
35-
if (project.Project.ProjectStack.replacedBy) {
36-
// need to add audit logging
37-
try {
38-
const newStack = await app.db.models.ProjectStack.byId(project.Project.ProjectStack.replacedBy)
39-
app.log.info(`Updating project ${project.Project.id} to stack: '${newStack.hashid}'`)
40-
41-
const suspendOptions = {
42-
skipBilling: true
43-
}
44-
45-
app.db.controllers.Project.setInflightState(project.Project, 'starting')
46-
const result = await suspendProject(project.Project, suspendOptions)
47-
48-
await project.Project.setProjectStack(newStack)
49-
await project.Project.save()
50-
51-
await app.auditLog.Project.project.stack.changed(null, null, project.Project, newStack)
52-
53-
await unSuspendProject(project.Project, result.resumeProject, result.targetState)
54-
} catch (err) {
55-
app.log.info(`Problem updating project ${project.Project.id} - ${err.toString()}`)
56-
}
57-
}
5856
}
5957
}
6058
}

forge/ee/routes/autoUpdateStacks/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = async function (app) {
5353
properties: {
5454
hour: { type: 'number' },
5555
day: { type: 'number' },
56-
restartOnly: { type: 'boolean' }
56+
restart: { type: 'boolean' }
5757
}
5858
}
5959
},
@@ -103,7 +103,7 @@ module.exports = async function (app) {
103103
properties: {
104104
hour: { type: 'number' },
105105
day: { type: 'number' },
106-
restartOnly: { type: 'boolean' }
106+
restart: { type: 'boolean' }
107107
}
108108
}
109109
}
@@ -117,7 +117,7 @@ module.exports = async function (app) {
117117
properties: {
118118
hour: { type: 'number' },
119119
day: { type: 'number' },
120-
restartOnly: { type: 'boolean' }
120+
restart: { type: 'boolean' }
121121
}
122122
}
123123
},
@@ -133,7 +133,7 @@ module.exports = async function (app) {
133133
}
134134
try {
135135
for (const d of request.body.schedule) {
136-
await request.project.updateSetting(`${KEY_STACK_UPGRADE_HOUR}_${d.day}`, { hour: d.hour, restartOnly: d.restartOnly })
136+
await request.project.updateSetting(`${KEY_STACK_UPGRADE_HOUR}_${d.day}`, { hour: d.hour, restart: d.restart })
137137
}
138138
} catch (err) {
139139
return reply

frontend/src/pages/instance/Settings/Maintenance.vue

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55
<FormHeading>Scheduled Restarts/Upgrades</FormHeading>
66
<FormRow v-model="scheduledUpgrade.enabled" :disabled="!allowDisable" type="checkbox" class="mt-5" container-class="max-w-xl">
77
Enabled
8+
<template #description>
9+
Select the days of the week and the hour during which the automatic upgrade will occur if available. The upgrade will start within the selected hour.
10+
</template>
11+
</FormRow>
12+
<FormRow v-model="scheduledUpgrade.restart" :disabled="!scheduledUpgrade.enabled" type="checkbox">
13+
Restart Even if no update available
14+
<template #description>
15+
This will trigger a Node-RED restart even if no update is available.
16+
</template>
817
</FormRow>
9-
<ff-radio-group v-model="scheduledUpgrade.restartOnly" orientation="vertical" :options="options" />
1018
<p class="my-3"><span class="font-bold">Note:</span> All times are stated in UTC.</p>
1119
<div class="my-5 flex flex-col gap-5 max-w-xl">
1220
<!-- <pre>{{ scheduledUpgrade }}</pre> -->
@@ -79,7 +87,7 @@ export default {
7987
return {
8088
scheduledUpgrade: {
8189
enabled: false,
82-
restartOnly: 0,
90+
restart: false,
8391
startHour: null,
8492
selectedWeekdays: [],
8593
initialValue: null
@@ -137,22 +145,6 @@ export default {
137145
allowDisable () {
138146
// Team can disable if the autoStackUpdate flag is not explicitly false
139147
return !this.scheduledUpgrade.enabled || this.team.type.properties?.autoStackUpdate?.allowDisable !== false
140-
},
141-
options () {
142-
return [
143-
{
144-
label: 'Apply upgrades when available',
145-
value: 0,
146-
disabled: !this.scheduledUpgrade.enabled,
147-
description: 'Select the days of the week and the hour during which the automatic upgrade will occur if available. The upgrade will start within the selected hour.'
148-
},
149-
{
150-
label: 'Restart Node-RED at scheduled time',
151-
value: 1,
152-
disabled: !this.scheduledUpgrade.enabled,
153-
description: 'Select the days of the week and the hour during which the Node-RED instance will be restarted. The restart will occur within the selected hour.'
154-
}
155-
]
156148
}
157149
},
158150
watch: {
@@ -233,7 +225,7 @@ export default {
233225
this.scheduledUpgrade.initialValue = {
234226
days: response.map(entry => entry.day),
235227
hour: response[0].hour, // use the first entry hour, they should all be the same
236-
restartOnly: response[0].restartOnly ? 1 : 0 // use the first entry restartOnly, they should all be the same
228+
restart: response[0].restart // use the first entry restart, they should all be the same
237229
}
238230
this.scheduledUpgrade.initialValue.enabled = true
239231
@@ -244,14 +236,14 @@ export default {
244236
seconds: 0
245237
}
246238
this.scheduledUpgrade.enabled = true
247-
this.scheduledUpgrade.restartOnly = response[0].restartOnly ? 1 : 0 // use the first entry restartOnly, they should all be the same
239+
this.scheduledUpgrade.restart = response[0].restart // use the first entry restart, they should all be the same
248240
}).catch(error => {
249241
if (error.response.status === 404) {
250242
// Apply any defaults from the team type
251243
if (this.team.type.properties.autoStackUpdate?.days?.length > 0 && this.team.type.properties.autoStackUpdate?.hours?.length > 0) {
252244
this.scheduledUpgrade.initialValue = {
253245
enabled: false,
254-
restartOnly: 0
246+
restart: false
255247
}
256248
this.scheduledUpgrade.selectedWeekdays = [...this.team.type.properties.autoStackUpdate.days]
257249
this.scheduledUpgrade.initialValue.days = [...this.team.type.properties.autoStackUpdate.days]
@@ -269,7 +261,7 @@ export default {
269261
this.scheduledUpgrade.startHour = null
270262
this.scheduledUpgrade.initialValue = {
271263
enabled: false,
272-
restartOnly: 0
264+
restart: false
273265
}
274266
}
275267
return
@@ -292,7 +284,7 @@ export default {
292284
return
293285
}
294286
295-
if (this.scheduledUpgrade.restartOnly !== this.scheduledUpgrade.initialValue.restartOnly) {
287+
if (this.scheduledUpgrade.restart !== this.scheduledUpgrade.initialValue.restart) {
296288
this.unsavedChanges = true
297289
return
298290
}
@@ -310,14 +302,14 @@ export default {
310302
const schedule = this.scheduledUpgrade.selectedWeekdays.map(day => ({
311303
hour: this.scheduledUpgrade.startHour.hours,
312304
day,
313-
restartOnly: this.scheduledUpgrade.restartOnly
305+
restart: this.scheduledUpgrade.restart
314306
}))
315307
return instanceApi.setUpdateSchedule(this.project.id, schedule)
316308
.then(() => {
317309
this.scheduledUpgrade.initialValue = {
318310
days: [...this.scheduledUpgrade.selectedWeekdays],
319311
hour: this.scheduledUpgrade.startHour.hours,
320-
restartOnly: this.scheduledUpgrade.restartOnly
312+
restart: this.scheduledUpgrade.restart
321313
}
322314
this.scheduledUpgrade.initialValue.enabled = true
323315
Alerts.emit('Schedule updated', 'confirmation')
@@ -331,7 +323,7 @@ export default {
331323
this.scheduledUpgrade.initialValue = null
332324
this.scheduledUpgrade.selectedWeekdays = null
333325
this.scheduledUpgrade.startHour = null
334-
this.scheduledUpgrade.restartOnly = false
326+
this.scheduledUpgrade.restart = false
335327
this.scheduledUpgrade.initialValue.enabled = false
336328
Alerts.emit('Schedule removed', 'confirmation')
337329
}).catch(error => {

0 commit comments

Comments
 (0)