# Path: src/myaas/settings.py
# DEBUG = config('MYAAS_DEBUG', default=False, cast=bool)
# 
# Path: src/myaas/utils/database.py
# def get_myaas_containers():
#     return filter(_is_database_container, list_containers())
# 
# def get_enabled_backend():
#     return importlib.import_module(settings.BACKEND)
# 
# Path: src/myaas/utils/container.py
# def find_container(name):
# def list_containers(all=True):
# def translate_host_basedir(path):
# def get_random_cpuset(cores_to_assign):
# def get_mapped_cpuset():


import signal
import logging
import click
from time import sleep
from datetime import datetime
from .settings import DEBUG
from .utils.database import get_myaas_containers, get_enabled_backend
from .utils.container import client
        return False

    def _is_expired(self, container):
        if 'com.myaas.expiresAt' in container['Labels']:
            expiry_ts = round(float(container['Labels']['com.myaas.expiresAt']))  # noqa
        else:
            # asume a 24 hours TTL
            expiry_ts = int(container['Created']) + 86400

        return datetime.utcnow() >= datetime.utcfromtimestamp(expiry_ts)

    def _is_dead(self, container):
        return container['State'] == 'exited'

    def _is_unhealthy(self, container):
        return 'unhealthy' in container['Status']


def remove_database(container):
    template = container['Labels']['com.myaas.template']
    name = container['Labels']['com.myaas.instance']
    try:
        logger.info(f'removing {name}')
        backend = get_enabled_backend().Database
        backend(client, template, name).remove()
    except Exception as e:
        logger.exception(
            f"Failed to remove database {template} {name}")



# Path: src/myaas/settings.py
# DEBUG = config('MYAAS_DEBUG', default=False, cast=bool)
# 
# Path: src/myaas/utils/database.py
# def get_myaas_containers():
#     return filter(_is_database_container, list_containers())
# 
# def get_enabled_backend():
#     return importlib.import_module(settings.BACKEND)
# 
# Path: src/myaas/utils/container.py
# def find_container(name):
# def list_containers(all=True):
# def translate_host_basedir(path):
# def get_random_cpuset(cores_to_assign):
# def get_mapped_cpuset():


# Path: src/myaas/reaper.py
import signal
import logging
import click
from time import sleep
from datetime import datetime
from .settings import DEBUG
from .utils.database import get_myaas_containers, get_enabled_backend
from .utils.container import client

        return False

    def _is_expired(self, container):
        if 'com.myaas.expiresAt' in container['Labels']:
            expiry_ts = round(float(container['Labels']['com.myaas.expiresAt']))  # noqa
        else:
            # asume a 24 hours TTL
            expiry_ts = int(container['Created']) + 86400

        return datetime.utcnow() >= datetime.utcfromtimestamp(expiry_ts)

    def _is_dead(self, container):
        return container['State'] == 'exited'

    def _is_unhealthy(self, container):
        return 'unhealthy' in container['Status']


def remove_database(container):
    template = container['Labels']['com.myaas.template']
    name = container['Labels']['com.myaas.instance']
    try:
        logger.info(f'removing {name}')
        backend = get_enabled_backend().Database
        backend(client, template, name).remove()
    except Exception as e:
        logger.exception(
            f"Failed to remove database {template} {name}")



@click.command()