How to use the apscheduler.schedulers.asyncio.AsyncIOScheduler 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 DeV1doR / ethereumd-proxy / ethereumd / server.py View on Github external
async def initialize_scheduler(app, loop):
            self._proxy = await create_ethereumd_proxy(self.endpoint,
                                                       loop=loop)
            self._poller = Poller(self._proxy, self.cmds, loop=loop)
            self._scheduler = AsyncIOScheduler({'event_loop': loop})
            if self._poller.has_blocknotify:
                self._scheduler.add_job(self._poller.blocknotify, 'interval',
                                        id='blocknotify',
                                        seconds=1)
            if self._poller.has_walletnotify:
                self._scheduler.add_job(self._poller.walletnotify, 'interval',
                                        id='walletnotify',
                                        seconds=1)
            if self._scheduler.get_jobs():
                self._scheduler.start()
        return initialize_scheduler
github UQComputingSociety / uqcsbot / uqcsbot / base.py View on Github external
def __init__(self, logger=None):
        self._user_token = None
        self._user_client = None
        self._bot_token = None
        self._bot_client = None
        self._verification_token = None
        self._executor = concurrent.futures.ThreadPoolExecutor()
        self.logger = logger or logging.getLogger("uqcsbot")
        self._handlers: DefaultDict[str, list] = collections.defaultdict(list)
        self._command_registry: DefaultDict[str, list] = collections.defaultdict(list)
        self._scheduler = AsyncIOScheduler()

        self.register_handler('message', self._handle_command)
        self.register_handler('hello', self._handle_hello)
        self.register_handler('goodbye', self._handle_goodbye)

        self.channels = ChannelWrapper(self)
        self.users = UsersWrapper(self)
github RasaHQ / rasa / rasa / core / jobs.py View on Github external
global __scheduler

    if not __scheduler:
        try:
            __scheduler = AsyncIOScheduler(event_loop=asyncio.get_event_loop())
            __scheduler.start()
            return __scheduler
        except UnknownTimeZoneError:
            warnings.warn(
                "apscheduler could not find a timezone and is "
                "defaulting to utc. This is probably because "
                "your system timezone is not set. "
                'Set it with e.g. echo "Europe/Berlin" > '
                "/etc/timezone"
            )
            __scheduler = AsyncIOScheduler(
                event_loop=asyncio.get_event_loop(), timezone=utc
            )
            __scheduler.start()
            return __scheduler
    else:
        # scheduler already created, make sure it is running on
        # the correct loop
        # noinspection PyProtectedMember
        if not __scheduler._eventloop == asyncio.get_event_loop():
            raise RuntimeError(
                "Detected inconsistent loop usage. "
                "Trying to schedule a task on a new event "
                "loop, but scheduler was created with a "
                "different event loop. Make sure there "
                "is only one event loop in use and that the "
                "scheduler is running on that one."
github erasaur / pnu / pnu / core / runnable.py View on Github external
def run_interval (self, func=None, update_interval=None):
        if update_interval is None and self._update_interval is None:
            raise ValueError("missing interval")

        if func is None:
            raise ValueError("missing func")

        scheduler = AsyncIOScheduler()
        scheduler.add_job(
            func,
            'interval',
            seconds=self._update_interval
        )
        scheduler.start()
github aiogram / bot / app / services / apscheduller.py View on Github external
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from pytz import utc

from app import config

DEFAULT = "default"

jobstores = {
    DEFAULT: RedisJobStore(
        db=config.REDIS_DB_JOBSTORE, host=config.REDIS_HOST, port=config.REDIS_PORT
    )
}
executors = {DEFAULT: AsyncIOExecutor()}
job_defaults = {"coalesce": False, "max_instances": 3, "misfire_grace_time": 3600}

scheduler = AsyncIOScheduler(
    jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone=utc
)


async def on_startup(dispatcher: Dispatcher):
    scheduler.start()


async def on_shutdown(dispatcher: Dispatcher):
    scheduler.shutdown()


def setup(executor: Executor):
    executor.on_startup(on_startup)
    executor.on_shutdown(on_shutdown)
github wasp / eureka / examples / eureka_heartbeat.py View on Github external
async def renew_lease(eureka):
    # Guarded to ensure one bad try doesn't kill
    # checkins for good.
    print('Renewing eureka lease')
    try:
        await eureka.renew()
        print('Renewed')
        return True
    except EurekaException as e:
        print('Error renewing registration:', e.status)
        return False


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    scheduler = AsyncIOScheduler(loop=loop)

    hostname = socket.gethostname()
    ip = socket.gethostbyname(hostname)

    eureka = EurekaClient('test-app', 5000, ip,
                          eureka_url='https://localhost:8761/eureka',
                          loop=loop)

    print('Registering...')
    loop.run_until_complete(eureka.register())
    print('Done')

    scheduler.add_job(renew_lease, 'interval', seconds=30, args=(eureka,))
    scheduler.start()

    try:
github c0rvax / project-black / server.py View on Github external
async def cb_instantiate_scheduler(app, loop):
        scheduler = AsyncIOScheduler()
        scheduler.add_job(HANDLERS.sender_loop, 'interval', seconds=1)
        scheduler.start()
github Firefly-Automation / Firefly / Firefly / helpers / scheduler.py View on Github external
def __init__(self):
    self._scheduler = AsyncIOScheduler()
    self._scheduler.start()
github tomoncle / PythonStudy / scheduler_task / study_apscheduler / examples / schedules / schdule.py View on Github external
def asyncio_schedule():
    """
    python version >= 3.4.0
    :return:
    """
    from apscheduler.schedulers.asyncio import AsyncIOScheduler
    try:
        import asyncio
    except ImportError:
        import trollius as asyncio

    def tick():
        print('Tick! The time is: %s' % datetime.now())

    scheduler = AsyncIOScheduler()
    scheduler.add_job(tick, 'interval', seconds=3)
    scheduler.start()
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))

    # Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
    try:
        asyncio.get_event_loop().run_forever()
    except (KeyboardInterrupt, SystemExit):
        pass
github Mausbiber / smartHome / libs / lib_timerswitch.py View on Github external
def restart(self):
        self._logging_daemon.info('TimerSwitch ... stopping for restart')
        self._scheduler.shutdown(0)
        self._scheduler = AsyncIOScheduler()
        self._scheduler.start()
        self.load()
        self._logging_daemon.info('TimerSwitch ... neu initialisiert')