# Path: libre/apps/scheduler/exceptions.py
# class AlreadyScheduled(Exception):
#     """
#     Raised when trying to schedule a Job instance of anything after it was
#     already scheduled in any other scheduler
#     """
#     pass
# 
# class UnknownJob(Exception):
#     pass
# 
# class UnknownJobClass(Exception):
#     """
#     Raised when trying to schedule a Job that is not of a a type:
#     IntervalJob or DateJob
#     """
#     pass


import logging
from apscheduler.scheduler import Scheduler as OriginalScheduler
from django.utils.translation import ugettext_lazy as _
from .exceptions import AlreadyScheduled, UnknownJob, UnknownJobClass
    def running(self):
        if self._scheduler:
            return self._scheduler.running
        else:
            return False

    def clear(self):
        for job in self.scheduled_jobs.values():
            self.stop_job(job)

    def stop_job(self, job):
        if self.running:
            self._scheduler.unschedule_job(job._job)

        del(self.scheduled_jobs[job.name])
        job.scheduler = None

    def _schedule_job(self, job):
        if isinstance(job, IntervalJob):
            job._job = self._scheduler.add_interval_job(job.function, *job.args, **job.kwargs)
        elif isinstance(job, DateJob):
            job._job = self._scheduler.add_date_job(job.function, *job.args, **job.kwargs)
        elif isinstance(job, CronJob):
            job._job = self._scheduler.add_cron_job(job.function, *job.args, **job.kwargs)
        else:
            raise UnknownJobClass

    def add_job(self, job):
        logger.debug('adding job')
        if job.scheduler or job.name in self.scheduled_jobs.keys():

# Path: libre/apps/scheduler/exceptions.py
# class AlreadyScheduled(Exception):
#     """
#     Raised when trying to schedule a Job instance of anything after it was
#     already scheduled in any other scheduler
#     """
#     pass
# 
# class UnknownJob(Exception):
#     pass
# 
# class UnknownJobClass(Exception):
#     """
#     Raised when trying to schedule a Job that is not of a a type:
#     IntervalJob or DateJob
#     """
#     pass


# Path: libre/apps/scheduler/classes.py
import logging
from apscheduler.scheduler import Scheduler as OriginalScheduler
from django.utils.translation import ugettext_lazy as _
from .exceptions import AlreadyScheduled, UnknownJob, UnknownJobClass

    def running(self):
        if self._scheduler:
            return self._scheduler.running
        else:
            return False

    def clear(self):
        for job in self.scheduled_jobs.values():
            self.stop_job(job)

    def stop_job(self, job):
        if self.running:
            self._scheduler.unschedule_job(job._job)

        del(self.scheduled_jobs[job.name])
        job.scheduler = None

    def _schedule_job(self, job):
        if isinstance(job, IntervalJob):
            job._job = self._scheduler.add_interval_job(job.function, *job.args, **job.kwargs)
        elif isinstance(job, DateJob):
            job._job = self._scheduler.add_date_job(job.function, *job.args, **job.kwargs)
        elif isinstance(job, CronJob):
            job._job = self._scheduler.add_cron_job(job.function, *job.args, **job.kwargs)
        else:
            raise UnknownJobClass

    def add_job(self, job):
        logger.debug('adding job')
        if job.scheduler or job.name in self.scheduled_jobs.keys():

            raise AlreadyScheduled