def scale_dyno(heroku_conn, heroku_app, heroku_dynos, heroku_proc, count): if count == 0: # we need to call the shutdown control_app shutdown_app(heroku_conn, heroku_app, heroku_dynos, heroku_proc) else: if NOTIFICATIONS: irc.send_irc_message("[%s] Scaling %s processes to %s" % (heroku_app.name, heroku_proc.type, count)) heroku_proc.scale(count)
def shutdown_app(heroku_conn, heroku_app, heroku_dynos, heroku_proc): running_already = 0 cmd = "fab celery.shutdown_process:%s" % heroku_proc.type for dyno in heroku_dynos: if dyno.command == cmd: running_already = 1 break if running_already == 1: print "[%s] Shutdown command for %s already running... skipping....".ljust(max_str_length) % (heroku_app.name, heroku_proc.type) else: print "[%s] shutting down processes %s".ljust(max_str_length) % (heroku_app.name, heroku_proc.type) if NOTIFICATIONS: irc.send_irc_message("[%s] shutting down processes %s" % (heroku_app.name, heroku_proc.type)) heroku_app.run_command_detached(cmd)
def shutdown_app(heroku_conn, heroku_app, heroku_dynos, heroku_proc): running_already = 0 cmd = "fab celery.shutdown_process:%s" % heroku_proc.type for dyno in heroku_dynos: if dyno.command == cmd: running_already = 1 break if running_already == 1: print "[%s] Shutdown command for %s already running... skipping....".ljust( max_str_length) % (heroku_app.name, heroku_proc.type) else: print "[%s] shutting down processes %s".ljust(max_str_length) % ( heroku_app.name, heroku_proc.type) if NOTIFICATIONS: irc.send_irc_message("[%s] shutting down processes %s" % (heroku_app.name, heroku_proc.type)) heroku_app.run_command_detached(cmd)
if app.appname in ratelimits: prev_limit = ratelimits[app.appname]['prev_limit'] prev_time = ratelimits[app.appname]['prev_time'] current_time = time.time() if (prev_limit - rl) > RATE_LIMIT_INTERVAL: time_diff = current_time - prev_time if time_diff > SLEEP_PERIOD: print "[{0}] ratelimit ({1}) is more than {4} lower than the previous rl ({2}), however no checks have been run for {3} seconds, proceeding....".format(app.appname, rl, prev_limit, time_diff) else: print "[{0}] skipping due to current ratelimit ({1}) being more than {3} lower than the previous rl ({2})".format(app.appname, rl, prev_limit) continue else: print "[{0}] ratelimit ({1}) is greater than the previous rl ({2}), proceeding....".format(app.appname, rl, prev_limit) if (rl < 100) and (rl > 90): irc.send_irc_message("[Proc_Scalar Warning] Heroku API RateLimit-Remaining = {0} for '{1}'".format(rl, key_type)) if rl < 25: print "[{0}] skipping due to ratelimit being too low {1}".format(app.appname, rl) continue applimits = {'prev_limit': rl, 'prev_time': time.time()} ratelimits[app.appname] = applimits heroku_apps = heroku_conn.apps() num_apps = len(apps) try: heroku_app = heroku_apps[app.appname] except KeyError: print "\n[ERROR] %s is not available via your configured HEROKU_API %s.\nAvailable apps are:-\n" % (app.appname, HEROKU_API_KEY) else:
if (prev_limit - rl) > RATE_LIMIT_INTERVAL: time_diff = current_time - prev_time if time_diff > SLEEP_PERIOD: print "[{0}] ratelimit ({1}) is more than {4} lower than the previous rl ({2}), however no checks have been run for {3} seconds, proceeding....".format( app.appname, rl, prev_limit, time_diff) else: print "[{0}] skipping due to current ratelimit ({1}) being more than {3} lower than the previous rl ({2})".format( app.appname, rl, prev_limit) continue else: print "[{0}] ratelimit ({1}) is greater than the previous rl ({2}), proceeding....".format( app.appname, rl, prev_limit) if (rl < 100) and (rl > 90): irc.send_irc_message( "[Proc_Scalar Warning] Heroku API RateLimit-Remaining = {0} for '{1}'" .format(rl, key_type)) if rl < 25: print "[{0}] skipping due to ratelimit being too low {1}".format( app.appname, rl) continue applimits = {'prev_limit': rl, 'prev_time': time.time()} ratelimits[app.appname] = applimits heroku_apps = heroku_conn.apps() num_apps = len(apps) try: heroku_app = heroku_apps[app.appname] except KeyError: