def display_scheduled_jobs(log):
    '''
        It's nice to see what's going on in the hours before the lights will be switched
        on or off.  So, display the scheduler Q on the following, cron style, schedule.
    '''
    crontimes = '7,19,20'
    Sched.get().add_cron_job(log_scheduled_jobs, hour=crontimes, minute=3, args=[log])
    log.info('Scheduled jobs will be logged per this (cron style - hourly) schedule: {}'.format(crontimes))
def job_already_scheduled(jobtime):
    '''
        Determine if a job is already scheduled
    '''
    jobs = Sched.get().get_jobs()
    found = False
    for job in jobs:
        pos = string.find(str(job), str(jobtime))
        if pos >= 0:
            found = True
            break
    return found
def schedule_next_cycle(log):
    '''
        After the scheduler runs the next required sunrise/sunset (turn) on/off
        cycle, it needs to re-schedule upcoming event(s).  We'll run a 'cron style' job
        twice every 24 hours - just in case we lose power and come
        back online.  Note: duplicate scheduler entries are avoided.
    '''
    sunrise, sunset = calc_sunrise_sunset(log)
    sched = Sched.get()
    if not job_already_scheduled(sunrise):
        sched.add_date_job(call_turn_off_ssr, sunrise, [log])
    if not job_already_scheduled(sunset):
        sched.add_date_job(call_turn_on_ssr, sunset, [log])
    log_scheduled_jobs(log)
def main():
    '''
        Main entry point.
    '''
    check_required_environment_vars()
    log = setup_logging()
    sched = Sched.get()  # snag a Scheduler instance
    log.info('>>')
    log.info('>>>>>>>>>>>>>>> AutoMaticLight starting <<<<<<<<<<<<<<<<')
    log.info('<<')
    log_inet_address(log)
    log_uptime(log)
    libratoapi = librato_connect()
    heartbeat(libratoapi)
    sched.add_interval_job(heartbeat, seconds=20, args=[libratoapi])
    schedule_next_cycle(log)
    sched.add_cron_job(schedule_next_cycle, hour='1,13', args=[log])
    log.info('Sunrise/Sunset calculation will run at 1:00AM and 1:00PM')
    sched.add_interval_job(log_inet_address, hours=24, args=[log])
    sched.add_interval_job(log_uptime, hours=24, args=[log])
    display_scheduled_jobs(log)
    set_current_state(log)
    return log
Beispiel #5
0
import Forecast as f
import Optimize as o
import Sched as s

import pandas as pd


#Per ATM
def ATM_Main(series,val_dates,holidays,model):
    
    forecasts = f.forecast(series,val_dates,holidays,weekly=0,monthly=monthly,cpoint=cpoint)
    optimal  = o.optimize
        (b,d,reload_amt,
                 atm_no,days_no,reload_charge=2000, r=0.05/365,t=0,t_day0=0)
    
    decision = s.decision()
    
    
    return dataframme




#Error Check
def Check(date,holiday_file,model_file,atm_list="All",horizon=7,raw_path,out_path):
    
    
    #assumes same list of Holidays and Payrolls for all models
    
    sdate
    edate
def log_scheduled_jobs(log):
    jobs = Sched.get().get_jobs()
    for job in jobs:
        log.info('Job %s' % str(job))