Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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)
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."
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()
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)
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:
async def cb_instantiate_scheduler(app, loop):
scheduler = AsyncIOScheduler()
scheduler.add_job(HANDLERS.sender_loop, 'interval', seconds=1)
scheduler.start()
def __init__(self):
self._scheduler = AsyncIOScheduler()
self._scheduler.start()
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
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')