-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathmaintenance.js
More file actions
58 lines (48 loc) · 2.4 KB
/
maintenance.js
File metadata and controls
58 lines (48 loc) · 2.4 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
'use strict'
const cli = require('heroku-cli-util')
module.exports = {
topic: 'redis',
command: 'maintenance',
needsApp: true,
needsAuth: true,
args: [{name: 'database', optional: true}],
flags: [
{name: 'window', char: 'w', description: 'set weekly UTC maintenance window', hasValue: true, optional: true},
{name: 'run', description: 'start maintenance', optional: true},
{name: 'force', char: 'f', description: 'start maintenance without entering application maintenance mode', optional: true},
],
description: 'manage maintenance windows',
help: 'Set or change the maintenance window for your Redis instance',
run: cli.command(async (context, heroku) => {
const api = require('../lib/shared')(context, heroku)
let addon = await api.getRedisAddon()
let newPluginMessage = `You can also manage maintenances on your Redis instance with ${cli.color.cmd('data:maintenances')}.`
newPluginMessage += '\nFollow https://devcenter.heroku.com/articles/data-maintenance-cli-commands'
newPluginMessage += `\nto install the ${cli.color.cyan('Data Maintenance CLI plugin')}.`
cli.warn(newPluginMessage)
// eslint-disable-next-line no-eq-null, eqeqeq
if (addon.plan.name.match(/mini/) != null) {
cli.exit(1, 'The redis:maintenance command is not available for Mini plans')
}
if (context.flags.window) {
// eslint-disable-next-line no-eq-null, eqeqeq
if (context.flags.window.match(/[A-Za-z]{3,10} \d\d?:[03]0/) == null) {
cli.exit(1, 'Maintenance windows must be "Day HH:MM", where MM is 00 or 30.')
}
let maintenance = await api.request(`/redis/v0/databases/${addon.name}/maintenance_window`, 'PUT', {description: context.flags.window})
cli.log(`Maintenance window for ${addon.name} (${addon.config_vars.join(', ')}) set to ${maintenance.window}.`)
cli.exit(0)
}
if (context.flags.run) {
let app = await heroku.get(`/apps/${context.app}`)
if (!app.maintenance && !context.flags.force) {
cli.exit(1, 'You must put your application in maintenance mode, or use the redis:maintenance --run --force command.')
}
let maintenance = await api.request(`/redis/v0/databases/${addon.name}/maintenance`, 'POST')
cli.log(maintenance.message)
cli.exit(0)
}
let maintenance = await api.request(`/redis/v0/databases/${addon.name}/maintenance`, 'GET', null)
cli.log(maintenance.message)
}),
}