How to use the apscheduler.events.SchedulerEvent function in APScheduler

To help you get started, we’ve selected a few APScheduler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agronholm / apscheduler / tests / testscheduler.py View on Github external
def test_add_listener(self):
        val = []
        self.scheduler.add_listener(val.append)

        event = SchedulerEvent(EVENT_SCHEDULER_START)
        self.scheduler._notify_listeners(event)
        eq_(len(val), 1)
        eq_(val[0], event)

        event = SchedulerEvent(EVENT_SCHEDULER_SHUTDOWN)
        self.scheduler._notify_listeners(event)
        eq_(len(val), 2)
        eq_(val[1], event)

        self.scheduler.remove_listener(val.append)
        self.scheduler._notify_listeners(event)
        eq_(len(val), 2)
github agronholm / apscheduler / tests / testscheduler.py View on Github external
def test_add_listener(self):
        val = []
        self.scheduler.add_listener(val.append)

        event = SchedulerEvent(EVENT_SCHEDULER_START)
        self.scheduler._notify_listeners(event)
        eq_(len(val), 1)
        eq_(val[0], event)

        event = SchedulerEvent(EVENT_SCHEDULER_SHUTDOWN)
        self.scheduler._notify_listeners(event)
        eq_(len(val), 2)
        eq_(val[1], event)

        self.scheduler.remove_listener(val.append)
        self.scheduler._notify_listeners(event)
        eq_(len(val), 2)
github agronholm / apscheduler / tests / test_scheduler.py View on Github external
def test_add_listener(self, sched):
        val = []
        sched.add_listener(val.append)

        event = SchedulerEvent(EVENT_SCHEDULER_START)
        sched._notify_listeners(event)
        assert len(val) == 1
        assert val[0] == event

        event = SchedulerEvent(EVENT_SCHEDULER_SHUTDOWN)
        sched._notify_listeners(event)
        assert len(val) == 2
        assert val[1] == event

        sched.remove_listener(val.append)
        sched._notify_listeners(event)
        assert len(val) == 2
github agronholm / apscheduler / apscheduler / schedulers / base.py View on Github external
:param str|unicode jobstore: alias of the job store

        """
        with self._jobstores_lock:
            if self.state == STATE_STOPPED:
                if jobstore:
                    self._pending_jobs = [pending for pending in self._pending_jobs if
                                          pending[1] != jobstore]
                else:
                    self._pending_jobs = []
            else:
                for alias, store in self._jobstores.items():
                    if jobstore in (None, alias):
                        store.remove_all_jobs()

        self._dispatch_event(SchedulerEvent(EVENT_ALL_JOBS_REMOVED, jobstore))
github agronholm / apscheduler / apscheduler / schedulers / base.py View on Github external
def resume(self):
        """Resume job processing in the scheduler."""
        if self.state == STATE_STOPPED:
            raise SchedulerNotRunningError
        elif self.state == STATE_PAUSED:
            self.state = STATE_RUNNING
            self._logger.info('Resumed scheduler job processing')
            self._dispatch_event(SchedulerEvent(EVENT_SCHEDULER_RESUMED))
            self.wakeup()
github agronholm / apscheduler / apscheduler / schedulers / base.py View on Github external
def pause(self):
        """
        Pause job processing in the scheduler.

        This will prevent the scheduler from waking up to do job processing until :meth:`resume`
        is called. It will not however stop any already running job processing.

        """
        if self.state == STATE_STOPPED:
            raise SchedulerNotRunningError
        elif self.state == STATE_RUNNING:
            self.state = STATE_PAUSED
            self._logger.info('Paused scheduler job processing')
            self._dispatch_event(SchedulerEvent(EVENT_SCHEDULER_PAUSED))
github agronholm / apscheduler / apscheduler / schedulers / base.py View on Github external
alias)

            if isinstance(executor, BaseExecutor):
                self._executors[alias] = executor
            elif isinstance(executor, str):
                self._executors[alias] = executor = self._create_plugin_instance(
                    'executor', executor, executor_opts)
            else:
                raise TypeError('Expected an executor instance or a string, got %s instead' %
                                executor.__class__.__name__)

            # Start the executor right away if the scheduler is running
            if self.state != STATE_STOPPED:
                executor.start(self, alias)

        self._dispatch_event(SchedulerEvent(EVENT_EXECUTOR_ADDED, alias))
github agronholm / apscheduler / apscheduler / schedulers / base.py View on Github external
raise SchedulerNotRunningError

        self.state = STATE_STOPPED

        # Shut down all executors
        with self._executors_lock:
            for executor in self._executors.values():
                executor.shutdown(wait)

        # Shut down all job stores
        with self._jobstores_lock:
            for jobstore in self._jobstores.values():
                jobstore.shutdown()

        self._logger.info('Scheduler has been shut down')
        self._dispatch_event(SchedulerEvent(EVENT_SCHEDULER_SHUTDOWN))
github agronholm / apscheduler / apscheduler / schedulers / base.py View on Github external
if isinstance(jobstore, BaseJobStore):
                self._jobstores[alias] = jobstore
            elif isinstance(jobstore, str):
                self._jobstores[alias] = jobstore = self._create_plugin_instance(
                    'jobstore', jobstore, jobstore_opts)
            else:
                raise TypeError('Expected a job store instance or a string, got %s instead' %
                                jobstore.__class__.__name__)

            # Start the job store right away if the scheduler isn't stopped
            if self.state != STATE_STOPPED:
                jobstore.start(self, alias)

        # Notify listeners that a new job store has been added
        self._dispatch_event(SchedulerEvent(EVENT_JOBSTORE_ADDED, alias))

        # Notify the scheduler so it can scan the new job store for jobs
        if self.state != STATE_STOPPED:
            self.wakeup()
github agronholm / apscheduler / apscheduler / schedulers / base.py View on Github external
# Create a default job store if nothing else is configured
            if 'default' not in self._jobstores:
                self.add_jobstore(self._create_default_jobstore(), 'default')

            # Start all the job stores
            for alias, store in self._jobstores.items():
                store.start(self, alias)

            # Schedule all pending jobs
            for job, jobstore_alias, replace_existing in self._pending_jobs:
                self._real_add_job(job, jobstore_alias, replace_existing)
            del self._pending_jobs[:]

        self.state = STATE_PAUSED if paused else STATE_RUNNING
        self._logger.info('Scheduler started')
        self._dispatch_event(SchedulerEvent(EVENT_SCHEDULER_START))

        if not paused:
            self.wakeup()