Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASG Suspend #37

Open
wants to merge 155 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
d8a0a5a
first cut
dyaxley Sep 26, 2019
9282775
first cut
dyaxley Sep 26, 2019
f61fd37
Test out asg suspend
dyaxley Sep 26, 2019
582baa2
Test out asg suspend
dyaxley Sep 26, 2019
5106c11
rejig functions
dyaxley Sep 26, 2019
871fd8d
update func name
dyaxley Sep 26, 2019
cf937b2
dryrun
dyaxley Sep 26, 2019
c43fb90
test suspending
dyaxley Sep 26, 2019
37ca8fb
added suspend and resume to iam
dyaxley Sep 26, 2019
a4e2625
instances as array
dyaxley Sep 26, 2019
c3b1c78
update array
dyaxley Sep 26, 2019
26da142
fix the resume
dyaxley Sep 27, 2019
b832da4
resume?
dyaxley Sep 27, 2019
d107aaf
log inst
dyaxley Sep 27, 2019
79f8203
fix resume issue in start.js
dyaxley Sep 27, 2019
7145d6d
logg everything
dyaxley Sep 27, 2019
d55fa42
update iam to include kms create grant to allow lamda to start encryp…
dyaxley Sep 27, 2019
896dfec
minor update
dyaxley Sep 27, 2019
9ce3044
Update to suspend all processes
dyaxley Oct 17, 2019
cf3781d
Added weekend off param
dyaxley Oct 17, 2019
796418d
default to false
dyaxley Oct 17, 2019
4f0e406
default to false
dyaxley Oct 17, 2019
4b15335
hmmm
dyaxley Oct 17, 2019
10e07bd
clean up function
dyaxley Oct 17, 2019
3049a2d
fix cron days
dyaxley Oct 17, 2019
7d93b0c
temp fix
dyaxley Oct 17, 2019
0be98ec
add comment
dyaxley Oct 17, 2019
dc3d302
update function
dyaxley Oct 17, 2019
7a7f111
update tests
dyaxley Oct 18, 2019
8bc8690
updates to weekendsOff logic to support timezones & updates to npm pa…
dyaxley Nov 20, 2019
2e8d1b2
fix up linting
dyaxley Nov 20, 2019
34b4848
updates to var name
dyaxley Nov 20, 2019
9c41d18
added some tests for asg suspend
dyaxley Nov 20, 2019
24fdcc6
added tests for asg suspend feature
dyaxley Nov 20, 2019
b4069d1
Updates to readme
dyaxley Nov 20, 2019
3fcf6d4
Merge branch 'master' into asgSuspend
petercrotty Feb 9, 2023
d6082ec
W2C-453 - move code
petercrotty Feb 9, 2023
e3ce7e6
Debug
petercrotty Feb 9, 2023
b4440bf
Get cron dates working again
petercrotty Feb 12, 2023
1bac343
Correct days of the week
petercrotty Feb 26, 2023
a1e0349
Retry when RequestLimitExceeded
petercrotty Feb 27, 2023
25d975f
Add logging
petercrotty Mar 1, 2023
5463f13
Add more error handling
petercrotty Mar 22, 2023
7de0939
Correct syntax
petercrotty Mar 22, 2023
90f8c7a
Correct syntax
petercrotty Mar 22, 2023
040f4af
Correct syntax
petercrotty Mar 22, 2023
eb41079
Correct syntax
petercrotty Mar 22, 2023
cd6cc17
Add more error handling
petercrotty Mar 23, 2023
41e6b2f
Add more error handling
petercrotty Mar 24, 2023
4361818
Try different Params for deleteTag
petercrotty Mar 24, 2023
8a55518
add sleep between the stop process
katevucmd Jun 22, 2023
1150561
ahhhhhhhhhhhhhhhhhhhhhhhhhhhh
katevucmd Jun 26, 2023
a989ed3
upgrade version
katevucmd Jun 28, 2023
87122fd
add sleep function
katevucmd Jun 28, 2023
3407051
fix import function
katevucmd Jun 28, 2023
9fcdafc
fix import function?
katevucmd Jun 28, 2023
ea74f2a
fix import function?
katevucmd Jun 28, 2023
0098e72
add filter for stop function :fingercrossed
katevucmd Jun 29, 2023
4b12a35
comment unused function
katevucmd Jun 29, 2023
5ee2f1c
add filter for stopasg and stop instances
katevucmd Jun 29, 2023
6a06d94
increase timeout
katevucmd Jun 29, 2023
8d82f87
fix filter for tag
katevucmd Jun 29, 2023
ebc0463
wrong tag name :(((((
katevucmd Jun 29, 2023
4b2db77
comment filter by operating hour and add more log
katevucmd Jun 29, 2023
b0901bf
add more comment
katevucmd Jun 29, 2023
a7a9387
test with promise
katevucmd Jun 29, 2023
d884c5c
test with promise
katevucmd Jun 29, 2023
e92147d
fix?
katevucmd Jun 29, 2023
d5ea1b3
fix?
katevucmd Jun 29, 2023
b1bb555
promise
katevucmd Jun 29, 2023
b00744a
promise
katevucmd Jun 29, 2023
f5f00cf
promise
katevucmd Jun 29, 2023
fd4814b
promise
katevucmd Jun 29, 2023
494bebf
promise
katevucmd Jun 29, 2023
761e77c
promise
katevucmd Jun 29, 2023
f06ae39
promise
katevucmd Jun 29, 2023
75b853b
promise
katevucmd Jun 29, 2023
a048535
promise
katevucmd Jun 29, 2023
3351811
promise
katevucmd Jun 29, 2023
bf3c489
promise
katevucmd Jun 29, 2023
f33b354
promise
katevucmd Jun 29, 2023
2c96db0
promise
katevucmd Jun 29, 2023
35d17c0
promise
katevucmd Jun 29, 2023
566bd9f
passing application into filter function
katevucmd Jun 29, 2023
9e4aa7d
add more comments
katevucmd Jun 30, 2023
e13aec8
update start function
katevucmd Jun 30, 2023
e7d85f7
add variable for sleepTing
katevucmd Jun 30, 2023
d9d54ec
test get list of instances
katevucmd Jun 30, 2023
148bdce
test get list of instances
katevucmd Jun 30, 2023
697a56a
test get list of instance
katevucmd Jun 30, 2023
77839f0
test get list of instance ahhhhhhhhhhhhhhhhhhdyiuuuiuy8787687ylhfudasyf
katevucmd Jun 30, 2023
6818f5a
why it does not pass the varialbe why why why why
katevucmd Jun 30, 2023
59acf0b
fix type of params
katevucmd Jun 30, 2023
a31c7aa
limit to specific slice for testing
katevucmd Jun 30, 2023
ac1bb4d
limit to specific slice for testing for start
katevucmd Jun 30, 2023
70df84b
fix for list asg for suspend
katevucmd Jun 30, 2023
2f38ac9
fix for list asg for suspend for start
katevucmd Jun 30, 2023
7a607fe
fix import function
katevucmd Jun 30, 2023
e26858c
test with option all for asg
katevucmd Jun 30, 2023
1959d9c
test with option all for asg
katevucmd Jun 30, 2023
01d4d3e
now we test the stop for real - limit to specific whics_env
katevucmd Jun 30, 2023
045ce12
set dryrun = false does not work?
katevucmd Jun 30, 2023
9ccb322
using env in lambda for dryrun
katevucmd Jun 30, 2023
126b8fa
console.log dryrRUn env
katevucmd Jun 30, 2023
1e19199
fix passing env
katevucmd Jun 30, 2023
0aca552
fix passing env
katevucmd Jun 30, 2023
62fb462
fix passing env for start
katevucmd Jun 30, 2023
fa55f91
trouble shooting start function
katevucmd Jun 30, 2023
d041a65
comment some for testing
katevucmd Jun 30, 2023
ab22909
another test
katevucmd Jun 30, 2023
1363779
test with filter for openning hours
katevucmd Jun 30, 2023
e5a634a
remove mock values for testing
katevucmd Jun 30, 2023
de1d5cc
update test
katevucmd Jul 1, 2023
3e01a35
update test
katevucmd Jul 1, 2023
c2a6426
promise again
katevucmd Jul 1, 2023
df3ac14
test
katevucmd Jul 1, 2023
090cc52
remove test
katevucmd Jul 1, 2023
6f0a974
Merge pull request #68 from nib-health-funds/W2C-636
katevucmd Jul 3, 2023
74881d6
set number of trying for retry function, update factors
katevucmd Jul 10, 2023
4486fb1
update
katevucmd Jul 10, 2023
704f6dc
update
katevucmd Jul 10, 2023
98bf0db
update
katevucmd Jul 10, 2023
d367000
try catch
katevucmd Jul 10, 2023
22f7591
try catch
katevucmd Jul 10, 2023
0a2c016
test
katevucmd Jul 10, 2023
58c3d01
test
katevucmd Jul 10, 2023
df28c41
promise
katevucmd Jul 10, 2023
801f8cd
promiseeeee
katevucmd Jul 10, 2023
584ee9a
yay it works
katevucmd Jul 10, 2023
debee1a
update some comment
katevucmd Jul 10, 2023
93e894c
clean
katevucmd Jul 11, 2023
c623ab8
clean
katevucmd Jul 11, 2023
3f1b03a
clean
katevucmd Jul 11, 2023
e7d8647
clean
katevucmd Jul 11, 2023
087a709
Merge pull request #69 from nib-health-funds/W2C-546
katevucmd Jul 11, 2023
c4e6145
add retry
katevucmd Jul 12, 2023
2a4b2f4
set up for testing
katevucmd Jul 12, 2023
d6e1a5d
reduce waiting time
katevucmd Jul 12, 2023
7e6b1f2
import retry
katevucmd Jul 12, 2023
2308ffd
fix path for import
katevucmd Jul 12, 2023
38cfa33
import retry
katevucmd Jul 12, 2023
78c7ea5
test promise again
katevucmd Jul 12, 2023
37ac38b
fix startInstances?
katevucmd Jul 12, 2023
4a65aef
add return
katevucmd Jul 12, 2023
8227939
remove wait
katevucmd Jul 12, 2023
50eb5a7
get list of instances for asg
katevucmd Jul 12, 2023
63855c6
get list of instances for asg
katevucmd Jul 12, 2023
fa53102
add some check?
katevucmd Jul 13, 2023
b2085da
start everything
katevucmd Jul 13, 2023
7d1525f
mock value for testing
katevucmd Jul 13, 2023
511aec8
remove some tag
katevucmd Jul 13, 2023
1175c8c
remove mock test
katevucmd Jul 13, 2023
570097c
reset waiting 4minutes
katevucmd Jul 13, 2023
1bdeaad
Merge pull request #70 from nib-health-funds/W2C-680
katevucmd Jul 13, 2023
7a33352
Merge branch 'master' into asgSuspend
petercrotty Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Edit [serverless.yml](serverless.yml) where you can adjust
- `hammertime:canttouchthis`: Will prevent hammertime from starting or stopping this asset in all cases.
- `hammertime:canttouchthisbetween`: Will prevent hammertime from starting or stopping the asset between a given time range specified in the value of the tag. The expected format for the value is `{datetime} and {datetime}` For example: A value of `2017-05-06 and 2017-06-06` prevents hammertime from affecting this asset between the mentioned dates. The datetimes should be a valid ISO-8601 string.
- `hammertime:canttouchthisbefore`: Will prevent hammertime from affecting the asset before a specific datetime represented in the value field of the tag. The datetime should be a valid ISO-8601 string. For example: A value of `2017-05-06` will ensure the given asset is not touched before the given date.
- `hammertime:asgsuspend`: (ASG only) Will suspend all processes on the tagged ASG and shutdown ec2 instances attached to ASG (this is instead of the default behaviour of setting desired instance count to 0, which terminates all ec2 instances).

`start-hammertime` will query the tags left by `stop-hammertime` and return the instances and ASGs to their previous status.

Expand Down
21 changes: 17 additions & 4 deletions events.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
const luxon = require('luxon');
const operatingTimezones = require('./operatingTimezones').timezones();
const isEnabled = require('./isEnabled').isEnabled;
const turnOffWeekends = require('./turnOffWeekends').turnOffWeekends;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably deserves to be in the readme


const START_HOUR = parseInt(process.env.HAMMERTIME_START_HOUR || '6', 10);
const STOP_HOUR = parseInt(process.env.HAMMERTIME_STOP_HOUR || '19', 10);

function getCronHour(hour, zone) {
return luxon.DateTime.fromObject({ hour, zone }).setZone('UTC').hour;
function getCronDayHour(day = '0', hour, zone) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be great to have test coverage of this one given it's fairly crucial to scheduling.

return {
day: luxon.DateTime.fromObject({ weekday: day, hour, zone }).setZone('UTC').weekdayShort,
hour: luxon.DateTime.fromObject({ weekday: day, hour, zone }).setZone('UTC').hour,
};
}

function getCron(hour, timezone) {
const week = {
dayBegin: getCronDayHour('1', hour, timezone).day,
dayEnd: getCronDayHour('5', hour, timezone).day,
};
const cronHour = getCronDayHour(hour, timezone).hour;
return (turnOffWeekends ? `cron(0 ${cronHour} ? * ${week.dayBegin}-${week.dayEnd} *)` : `cron(0 ${cronHour} * * ? *)`);
}

function stop() {
const stopCrons = operatingTimezones.map(timezone => ({
rate: `cron(0 ${getCronHour(STOP_HOUR, timezone)} * * ? *)`,
rate: getCron(STOP_HOUR, timezone),
enabled: isEnabled(),
input: {
currentOperatingTimezone: timezone,
Expand All @@ -24,7 +37,7 @@ function stop() {

function start() {
const startCrons = operatingTimezones.map(timezone => ({
rate: `cron(0 ${getCronHour(START_HOUR, timezone)} * * ? *)`,
rate: getCron(START_HOUR, timezone),
enabled: isEnabled(),
input: {
currentOperatingTimezone: timezone,
Expand Down
Loading