# Path: rpaas/scheduler.py
# DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
# class JobScheduler(threading.Thread):
#     def __init__(self, config=None, *args, **kwargs):
#     def get_last_run_key(self, key):
#     def try_lock(self):
#     def run(self):
#     def stop(self):
# 
# Path: rpaas/tasks.py
# def setup_redis_url():
# def initialize_celery():
#     def __init__(self, config=None):
#     def ensure_ready(self, name):
#     def remove(self, name):
#     def create(self, name):
#     def update(self, name, task_id):
#     def init_config(self, config=None):
#     def _get_conf(self, key, default=config.undefined):
#     def _add_host(self, name, lb=None):
#     def _delete_host(self, name, host, lb=None):
#     def run(self, config, name):
#     def _should_destroy_lb(self):
#     def run(self, config, name):
#     def run(self, config, name, quantity):
#     def run(self, config):
#     def _restore_machine(self, task, config, healthcheck_timeout):
#     def _failure_instances(self, retry_failure_query, retry_failure_delay):
#     def run(self, config):
#     def _check_machine_exists(self, address):
#     def run(self, config, name, plugin, csr, key, domain):
#     def run(self, config, name, plugin, domain):
#     def run(self, config):
#     def renew(self, cert, config):
#     def run(self, config):
#     def rotate_session_ticket(self, hosts):
#     def add_session_ticket(self, host, session_ticket):
# class NotReadyError(Exception):
# class TaskNotFoundError(Exception):
# class TaskManager(object):
# class BaseManagerTask(Task):
# class NewInstanceTask(BaseManagerTask):
# class RemoveInstanceTask(BaseManagerTask):
# class ScaleInstanceTask(BaseManagerTask):
# class RestoreMachineTask(BaseManagerTask):
# class CheckMachineTask(BaseManagerTask):
# class DownloadCertTask(BaseManagerTask):
# class RevokeCertTask(BaseManagerTask):
# class RenewCertsTask(BaseManagerTask):
# class SessionResumptionTask(BaseManagerTask):


import os
import time
from rpaas import scheduler, tasks
        super(RestoreMachine, self).__init__(config, *args, **kwargs)
        self.config = config or dict(os.environ)
        self.interval = int(self.config.get("RESTORE_MACHINE_RUN_INTERVAL", 30))
        self.last_run_key = self.get_last_run_key("RESTORE_MACHINE")

    def run(self):
        self.running = True
        while self.running:
            if self.try_lock():
                tasks.RestoreMachineTask().delay(self.config)
            time.sleep(self.interval / 2)


class CheckMachine(scheduler.JobScheduler):
    """
    CheckMachine detects machines where checks as marked 'critical' on
    Consul and creates tasks to be consumed by RestoreMachine.

    """

    def __init__(self, config=None, *args, **kwargs):
        super(CheckMachine, self).__init__(config, *args, **kwargs)
        self.config = config or dict(os.environ)
        self.interval = int(self.config.get("CHECK_MACHINE_RUN_INTERVAL", 30))
        self.last_run_key = self.get_last_run_key("CHECK_MACHINE")

    def run(self):
        self.running = True
        while self.running:
            if self.try_lock():

# Path: rpaas/scheduler.py
# DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
# class JobScheduler(threading.Thread):
#     def __init__(self, config=None, *args, **kwargs):
#     def get_last_run_key(self, key):
#     def try_lock(self):
#     def run(self):
#     def stop(self):
# 
# Path: rpaas/tasks.py
# def setup_redis_url():
# def initialize_celery():
#     def __init__(self, config=None):
#     def ensure_ready(self, name):
#     def remove(self, name):
#     def create(self, name):
#     def update(self, name, task_id):
#     def init_config(self, config=None):
#     def _get_conf(self, key, default=config.undefined):
#     def _add_host(self, name, lb=None):
#     def _delete_host(self, name, host, lb=None):
#     def run(self, config, name):
#     def _should_destroy_lb(self):
#     def run(self, config, name):
#     def run(self, config, name, quantity):
#     def run(self, config):
#     def _restore_machine(self, task, config, healthcheck_timeout):
#     def _failure_instances(self, retry_failure_query, retry_failure_delay):
#     def run(self, config):
#     def _check_machine_exists(self, address):
#     def run(self, config, name, plugin, csr, key, domain):
#     def run(self, config, name, plugin, domain):
#     def run(self, config):
#     def renew(self, cert, config):
#     def run(self, config):
#     def rotate_session_ticket(self, hosts):
#     def add_session_ticket(self, host, session_ticket):
# class NotReadyError(Exception):
# class TaskNotFoundError(Exception):
# class TaskManager(object):
# class BaseManagerTask(Task):
# class NewInstanceTask(BaseManagerTask):
# class RemoveInstanceTask(BaseManagerTask):
# class ScaleInstanceTask(BaseManagerTask):
# class RestoreMachineTask(BaseManagerTask):
# class CheckMachineTask(BaseManagerTask):
# class DownloadCertTask(BaseManagerTask):
# class RevokeCertTask(BaseManagerTask):
# class RenewCertsTask(BaseManagerTask):
# class SessionResumptionTask(BaseManagerTask):


# Path: rpaas/healing.py
import os
import time
from rpaas import scheduler, tasks

        super(RestoreMachine, self).__init__(config, *args, **kwargs)
        self.config = config or dict(os.environ)
        self.interval = int(self.config.get("RESTORE_MACHINE_RUN_INTERVAL", 30))
        self.last_run_key = self.get_last_run_key("RESTORE_MACHINE")

    def run(self):
        self.running = True
        while self.running:
            if self.try_lock():
                tasks.RestoreMachineTask().delay(self.config)
            time.sleep(self.interval / 2)


class CheckMachine(scheduler.JobScheduler):
    """
    CheckMachine detects machines where checks as marked 'critical' on
    Consul and creates tasks to be consumed by RestoreMachine.

    """

    def __init__(self, config=None, *args, **kwargs):
        super(CheckMachine, self).__init__(config, *args, **kwargs)
        self.config = config or dict(os.environ)
        self.interval = int(self.config.get("CHECK_MACHINE_RUN_INTERVAL", 30))
        self.last_run_key = self.get_last_run_key("CHECK_MACHINE")

    def run(self):
        self.running = True
        while self.running:
            if self.try_lock():

                tasks.CheckMachineTask().delay(self.config)