import logging

log = logging.getLogger(__name__)


def run(job):
    try:
        job.run()
    except Exception:
        log.warning("job failed")


def run_with_cleanup(job, lock):
    try:
        job.run()
    except:
        lock.release()
        raise


def run_all(jobs):
    for job in jobs:
        try:
            job.run()
        except BaseException as error:
            if isinstance(error, KeyboardInterrupt):
                raise
            log.exception("job failed")
