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

Nightly period #12

Closed
joeskop opened this issue Mar 8, 2018 · 11 comments
Closed

Nightly period #12

joeskop opened this issue Mar 8, 2018 · 11 comments

Comments

@joeskop
Copy link

joeskop commented Mar 8, 2018

Hi to everyone.

I have some instances that must be up during night and stopped during the day.
For example, an instance that must start art 19.00 and stop at 10.00. I tried with:

begintime 19:00
endtime 10:00
It doesn't works, beginperiod must be lower than endtime

1st period
begintime 19:00
endtime 00:00

2nd period
begintime 00:00
endtime 10:00
Doesn't works too. Only the 2nd period is working, the 1st is ignored.

Maybe anyone has a solution?
Best regards,

@arieleeuw
Copy link

For period 1 only specify the begin and no end time, that will work.
You can verify the scheduled periods using the scheduler-cli describe-schedule-usage command with the schedule and period you want to check. It tells you exactly in which periods your instance will be active.

@joeskop
Copy link
Author

joeskop commented Mar 8, 2018

Fantastic. It's true, I didn't try this solution before. Thank you!

@joeskop joeskop closed this as completed Mar 9, 2018
@joeskop joeskop reopened this Mar 9, 2018
@joeskop
Copy link
Author

joeskop commented Mar 9, 2018

Too fine to be true. It does not works.

SCHEDULE

descriptionString: Nightly-stop
nameString: nightly-stop
periodsStringSet[2]
0: backup-hours
1: backup-hours-2
timezoneString: Europe/Rome
typeString: schedule
use_metricsBoolean: true

PERIODS:

begintimeString: 19:00
descriptionString: Backup hours
nameString: backup-hours
typeString: period
use_metricsBoolean: true
weekdaysStringSet[1]
0: mon-sun

descriptionString: Backup hours 2
endtimeString: 10:00
nameString: backup-hours-2
typeString: period
use_metricsBoolean: true
weekdaysStringSet[1]
0: mon-sun

LOG

2018-03-09 - 11:00:16.434 - DEBUG : [ Instance EC2:i-xxxxxx (testserver) ]
2018-03-09 - 11:00:16.434 - DEBUG : Current state is running, instance type is c3.large, schedule is "nightly-stop"
2018-03-09 - 11:00:16.434 - DEBUG : Time used to determine desired for instance is Fri Mar 9 12:00:05 2018
2018-03-09 - 11:00:16.434 - DEBUG : Checking conditions for period "backup-hours-2"
2018-03-09 - 11:00:16.434 - DEBUG : [running] Weekday "fri" in weekdays (mon-sun)
2018-03-09 - 11:00:16.434 - DEBUG : [stopped] Time 12:00 is after stoptime 10:00, returned state is stopped
2018-03-09 - 11:00:16.434 - DEBUG : Checking conditions for period "backup-hours"
2018-03-09 - 11:00:16.434 - DEBUG : [running] Weekday "fri" in weekdays (mon-sun)
2018-03-09 - 11:00:16.434 - DEBUG : [running] Time 12:00 is before starttime 19:00, returned state is any
2018-03-09 - 11:00:16.434 - DEBUG : "Any" state period found for current time in schedule "nightly-stop", desired state is any
2018-03-09 - 11:00:16.434 - DEBUG : Desired state for instance from schedule "nightly-stop" is any, last desired state was stopped, actual state is running

Anyone with suggestions is welcome! Thank you!

@arieleeuw
Copy link

arieleeuw commented Mar 9, 2018

Can you try this:

scheduler-cli create-period --name period-1 --begintime 19:00 --endtime 23:59 --stack InstanceScheduler
{
   "Period": {
      "Endtime": "23:59", 
      "Type": "period", 
      "Name": "period-1", 
      "Begintime": "19:00"
   }
}


scheduler-cli create-period --name period-2 --begintime 00:00 --endtime 10:00 --stack InstanceScheduler
{
   "Period": {
      "Endtime": "10:00", 
      "Type": "period", 
      "Name": "period-2", 
      "Begintime": "00:00"
   }
}


scheduler-cli create-schedule --name every-night --periods period-1,period-2 --stack InstanceScheduler --timezone Europe/Rome
{
   "Schedule": {
      "RetainRunning": false, 
      "Enforced": false, 
      "Name": "every-night", 
      "StopNewInstances": true, 
      "Periods": [
         "period-1", 
         "period-2"
      ], 
      "Timezone": "Europe/Rome", 
      "Type": "schedule"
   }
}

You can simulate and see your savings using the following period that shows the running hours/periods in a defined period.

scheduler-cli describe-schedule-usage --name every-night --stack InstanceScheduler --startdate 20180301 --enddate 20180308
{
   "Usage": {
      "2018-03-01": {
         "BillingHours": 15, 
         "RunningPeriods": {
            "Period-1": {
               "Begin": "03/01/18 19:00:00", 
               "End": "03/01/18 23:59:00", 
               "BillingHours": 5, 
               "BillingSeconds": 17940
            }, 
            "Period-2": {
               "Begin": "03/01/18 00:00:00", 
               "End": "03/01/18 10:00:00", 
               "BillingHours": 10, 
               "BillingSeconds": 36000
            }
         }, 
         "BillingSeconds": 53940
      }, 
      "2018-03-02": {
         "BillingHours": 15, 
         "RunningPeriods": {
            "Period-1": {
               "Begin": "03/02/18 19:00:00", 
               "End": "03/02/18 23:59:00", 
               "BillingHours": 5, 
               "BillingSeconds": 17940
            }, 
            "Period-2": {
               "Begin": "03/02/18 00:00:00", 
               "End": "03/02/18 10:00:00", 
               "BillingHours": 10, 
               "BillingSeconds": 36000
            }
         }, 
         "BillingSeconds": 53940
      }, 
      "2018-03-03": {
         "BillingHours": 15, 
         "RunningPeriods": {
            "Period-1": {
               "Begin": "03/03/18 19:00:00", 
               "End": "03/03/18 23:59:00", 
               "BillingHours": 5, 
               "BillingSeconds": 17940
            }, 
            "Period-2": {
               "Begin": "03/03/18 00:00:00", 
               "End": "03/03/18 10:00:00", 
               "BillingHours": 10, 
               "BillingSeconds": 36000
            }
         }, 
         "BillingSeconds": 53940
      }, 
      "2018-03-04": {
         "BillingHours": 15, 
         "RunningPeriods": {
            "Period-1": {
               "Begin": "03/04/18 19:00:00", 
               "End": "03/04/18 23:59:00", 
               "BillingHours": 5, 
               "BillingSeconds": 17940
            }, 
            "Period-2": {
               "Begin": "03/04/18 00:00:00", 
               "End": "03/04/18 10:00:00", 
               "BillingHours": 10, 
               "BillingSeconds": 36000
            }
         }, 
         "BillingSeconds": 53940
      }, 
      "2018-03-05": {
         "BillingHours": 15, 
         "RunningPeriods": {
            "Period-1": {
               "Begin": "03/05/18 19:00:00", 
               "End": "03/05/18 23:59:00", 
               "BillingHours": 5, 
               "BillingSeconds": 17940
            }, 
            "Period-2": {
               "Begin": "03/05/18 00:00:00", 
               "End": "03/05/18 10:00:00", 
               "BillingHours": 10, 
               "BillingSeconds": 36000
            }
         }, 
         "BillingSeconds": 53940
      }, 
      "2018-03-06": {
         "BillingHours": 15, 
         "RunningPeriods": {
            "Period-1": {
               "Begin": "03/06/18 19:00:00", 
               "End": "03/06/18 23:59:00", 
               "BillingHours": 5, 
               "BillingSeconds": 17940
            }, 
            "Period-2": {
               "Begin": "03/06/18 00:00:00", 
               "End": "03/06/18 10:00:00", 
               "BillingHours": 10, 
               "BillingSeconds": 36000
            }
         }, 
         "BillingSeconds": 53940
      }, 
      "2018-03-07": {
         "BillingHours": 15, 
         "RunningPeriods": {
            "Period-1": {
               "Begin": "03/07/18 19:00:00", 
               "End": "03/07/18 23:59:00", 
               "BillingHours": 5, 
               "BillingSeconds": 17940
            }, 
            "Period-2": {
               "Begin": "03/07/18 00:00:00", 
               "End": "03/07/18 10:00:00", 
               "BillingHours": 10, 
               "BillingSeconds": 36000
            }
         }, 
         "BillingSeconds": 53940
      }, 
      "2018-03-08": {
         "BillingHours": 15, 
         "RunningPeriods": {
            "Period-1": {
               "Begin": "03/08/18 19:00:00", 
               "End": "03/08/18 23:59:00", 
               "BillingHours": 5, 
               "BillingSeconds": 17940
            }, 
            "Period-2": {
               "Begin": "03/08/18 00:00:00", 
               "End": "03/08/18 10:00:00", 
               "BillingHours": 10, 
               "BillingSeconds": 36000
            }
         }, 
         "BillingSeconds": 53940
      }
   }, 
   "Schedule": "every-night"
}

@hhh0505
Copy link

hhh0505 commented May 11, 2018

I have the exact same issue. Two periods , one that stops at 02:00 (lets call it abc) and one that starts at 08:00 (lets call it xyz)

So i assigned Schedule123 with periods {abc, xyz} but this doesnt work either. The state table for all tagged instances shows "any" state

i really would like to get this fixed or a solution for this.

@arieleeuw
Copy link

In order configure this you need the following periods

Tue-Sat, start 0:00, stop 2:00
Mon-Fri, start 08:00, stop 23:59

A schedule containing these periods

Starts at workdays at 8am and stops on the next day at 2am.
A fix for an issue that might stop/start at midnight has been deployed to aws answers from where you can update your stack

Regards,
Arie

@hhh0505
Copy link

hhh0505 commented May 11, 2018

Thanks for the reply, only issue with this is i have things running on these machines closer to 2am, if i run the proposed solution this will stop the instance at 23:59. If i am not mistaken?

@arieleeuw
Copy link

The latest maintenance release 2.2.2 that is on aws labs wil detect that there is an adjacent period at 0:00 and will keep the Instance running.

@hhh0505
Copy link

hhh0505 commented May 11, 2018

amazing, thanks for that info. Will try that out and report back.

edit this solution above worked. Thank you

@shsenior
Copy link
Contributor

Closing due to time elapsed since last correspondence. Please re-open this if you are still having an issue.

@KALX9
Copy link

KALX9 commented Feb 20, 2021

I have a similar situation. But here i don't want to mention the start or end time. I just want to mention the amount of time. Suppose if instance starts at 07:00 Hrs, it should be stopped after 2 Hours at 09:00 Hrs... or if it has started at 11:00 Hrs after 2 hours, it should stop at 13:00 Hrs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants