def scheduled_task(chat_id, notification_datetime, city): bot.bot.send_message(chat_id, weather.get_weather_report(city, 0)) scheduler.add_job(func=scheduled_task, trigger='date', run_date=notification_datetime, args=[chat_id, notification_datetime, city], id=chat_id) scheduler.start()
def initialize_cache(): from config import Config from app.api.events_cache import refresh_cache_thread, refresh_cache from app import scheduler, current_app # we'll set the run interval just little less than the CACHE TIMEOUT to avoid # the refresh be > CACHE_TIMEOUT logger.debug("initializing cache") refresh_cache(True) logger.debug("starting refresh thread") scheduler.add_job(refresh_cache_thread, 'interval', seconds=Config.CACHE_TIMEOUT - 10, args=[current_app._get_current_object()]) scheduler.start()
def run_tasks(): chat_id = str(request.args.get("chat_id")) hours = int(request.args.get("hours")) minutes = int(request.args.get("minutes")) city = request.args.get("city") local = pytz.timezone("Europe/Kiev") now = datetime.now(local) notification_datetime = now.replace(hour=int(hours), minute=int(minutes), second=0) if now > notification_datetime: notification_datetime = notification_datetime.replace(day=now.day + 1) scheduler.add_job(func=scheduled_task, trigger='date', run_date=notification_datetime, args=[chat_id, notification_datetime, city], id=chat_id) scheduler.start() return 'Scheduled several long running tasks.', 200
#!/usr/bin/env python # encoding: utf-8 from app import create_app from app import scheduler app = create_app() scheduler.start() if __name__ == "__main__": app.run(debug=True, host="0.0.0.0")
#!/usr/bin/env python from app import app, scheduler scheduler.start() app.run()
def main(): scheduler.add_job(schedule_job, 'interval', minutes=20) scheduler.start()
def start_scheduler(): scheduler.start() check_first()