amazon-archives / ec2-scheduler

The EC2 Scheduler uses a recurring Lambda function to automatically start and stop EC2 instances based on either default schedule or custom schedule defined per EC2 instance. - Now found at https://github.com/awslabs/aws-instance-scheduler
Other
148 stars 87 forks source link

Questions on nowMax parameter #3

Closed bshih-ixxus closed 7 years ago

bshih-ixxus commented 8 years ago

Hi,

I have two questions for ec2-scheduler.py and hope that you will explain to me.

(1) What is the logic behind the hardcoded 45min in nowMax as it is not mentioned anywhere? Is it to ensure that it will only start/stop within 45min of the specified start and stop time? What if someone schedules to run it on an hourly/daily basis?

          nowMax = datetime.datetime.now() - datetime.timedelta(minutes=45) 

(2) Because of the question above, I can't really see through the logic below:

Append to start list

                    if startTime >= str(nowMax) and startTime <= str(now) and \ 
                            isActiveDay == True and state == "stopped": 

Append to stop list

                    if stopTime >= str(nowMax) and stopTime <= str(now) and \ 
                         isActiveDay == True and state == "running":

If my startTime is 0800 and my instance is stopped , and it is now 15:00, so nowMax = 14:15. It will not be started because "startTime >= str(nowMax)" is not matched.

If my stopTime is 18:00 and my instance is running, and it is now 19:00, so nowMax = 18:15. It will not be stopped because "stopTime >= str(nowMax)" is not matched.

Many thanks in advance.

bob

groverlalit commented 8 years ago

Great question Bob. The assumption is the scheduler will run on either every 1, 5 or 15 min intervals. 45 min delta provides 3 retries for 15 min schedule. To avoid costs for an extra hour the stop time should usually be before 59th minute of the hour. I guess changing it from 45 to 59 would make more sense to capture 1 hour schedule also for the lambda. To avoid confusion, it would also make sense to a provide drop down menu in the CF template to choose from 1, 5, 15 or 60 min schedule.
Thanks again for bringing it up.

groverlalit commented 7 years ago

Resolved.