def load(): global loaded, avoid_flag, track_flag, last_rotate # car.set_global_speed(5) avoid_flag = 0 track_flag = 1 last_rotate = 0 if not loaded: car.on_track_detector_change(track_detector_callback) # car.on_infrared_sensor_change(simple_avoid_ob) car.on_ultrasonic_in_range(simple_avoid_ob_from_ultrasonic, 0, 25) scheduler.start() loaded = True
def start(): configure(os.environ["LOG_LEVEL"]) if "BUILD_VERSION" in os.environ.keys(): logging.info("BUILD VERSION IS %s", os.environ["BUILD_VERSION"]) if not "INTERVAL" in os.environ.keys(): raise AssertionError("Cron expression is not set") logging.debug("Scheduler is enabled. Task will be scheduled to run at %s", os.environ["INTERVAL"]) scheduler.configure(os.environ["INTERVAL"], pause_verify_nzb) scheduler.start()
def main(): tornado.options.parse_command_line() app = tornado.httpserver.HTTPServer(Application()) app.listen(options.port) scheduler = TornadoScheduler() consultationCron=CronTrigger(second='0',minute='*/15',hour='*') #每隔15分钟刷新一次 scheduler.add_job(consultation,consultationCron) #添加任务 noticeUpdateCron=CronTrigger(second='0',minute='0',hour='8') # scheduler.add_job(noticeUpdate,noticeUpdateCron) #添加任务 timeoutCron=CronTrigger(second='0',minute='30',hour='23') # scheduler.add_job(timeout,timeoutCron) #添加任务 scheduler.add_listener(scheduler_listener, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR) #调度运行监听 scheduler.start() #启动调度 tornado.ioloop.IOLoop.instance().start()#启动服务
async def on_startup(app): webhook = await bot.get_webhook_info() print(await bot.me) if webhook.url != WEBHOOK_URL: if not webhook.url: await bot.delete_webhook() await bot.set_webhook(WEBHOOK_URL, certificate=open(SSL_CERT, 'rb')) asyncio.ensure_future(scheduler.start()) # its ok
def run(self): try: self.camera.start() except SystemError: return False scheduler.start(self.jobs, daemon=True) try: open('cam.lck','w').close() while True: time.sleep(1) try: open('cam.lck').close() except IOError: raise KeyboardInterrupt except KeyboardInterrupt: print 'CamScheduler terminated.' self.camera.stop() finally: return True
def disk_space_calc(directories, free, threshold, log_level, remote_path_mapping, rclone_url, source_remote, dest_remote, auth_user, auth_password, dry_run, scheduled, healthcheck, logfile): """ Check free disk space and return a list of files to be moved/deleted from disk to reach a desired threshold of free space. """ configure(log_level, logfile) if "BUILD_VERSION" in os.environ.keys(): logging.info("DISK SCANNER BUILD %s", os.environ["BUILD_VERSION"]) if not scheduled: logging.debug("One time execution is enabled.") do_calculation_and_move(directories, free, threshold, remote_path_mapping, rclone_url, source_remote, dest_remote, auth_user, auth_password, dry_run) if scheduled: logging.debug( "Scheduler is enabled. Task will be scheduled to run at %s", scheduled) scheduler.configure(scheduled, wrap_with_healthcheck(lambda: do_calculation_and_move(directories, free, threshold, remote_path_mapping, rclone_url, source_remote, dest_remote, auth_user, auth_password, dry_run), healthcheck)) scheduler.start()
logging.basicConfig(format="%(asctime)s %(message)s", filename="request.log") # Set default interval or validate value from command line args if len(sys.argv) == 1: interval = 10 else: if validator.is_stringinteger(sys.argv[1]): interval = int(sys.argv[1]) else: print "First parameter must be value for poll interval in seconds." print "Please enter integer as first parameter." print "Example: python main.py 60" sys.exit(1) if interval < 10: print "Setting poll interval to the minimum of 10 seconds." interval = 10 # Initialize config object to be passed around # It contains access to our WebPage objects conf = config.Config() conf.initialize() # Start the web server web_server.conf = conf thread.start_new_thread(web_server.start, ()) # Start main polling loop scheduler.start(interval, conf)
@app.route('/notification', methods=['POST']) def notification(): root = et.fromstring(request.data) video_id = root.find('./atom:entry/yt:videoId', s.NAMESPACES).text video_link = root.find('./atom:entry/atom:link', s.NAMESPACES).get('href') video_title = root.find('./atom:entry/atom:title', s.NAMESPACES).text bot.log_message('POST Notification of %s.' % video_id) if (not db.Notifications.find_one({'video_id': video_id, 'notification': False })): db.Notifications.insert_one({'video_id': video_id, 'video_title': video_title, 'video_link': video_link, 'notification': False}) bot.send_simple_notification(video_id, video_title, video_link) db.Notifications.update_one({'video_id': video_id}, {'notification': True}) return 'Notification Received, sent to Telegram channel.' else: return 'Notification Received and ignored.' @app.route('/subscribe') def subscribe(): channel = request.args.get('channel_id') mode = request.args.get('sub', default='True') request_subscription(channel, mode == 'True') return 'Done.' keep_alive_start() scheduler.add_job(func=renew_subscriptions) scheduler.start() renew_subscriptions()
""" WSGI config for dynomonitor project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ """ import os import sys import subprocess from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dynomonitor.settings') application = get_wsgi_application() from scheduler import start start() if bool(int(os.environ.get('RUN_WITHIN_WEB', 0))): subprocess.Popen([sys.executable, 'monitor.py'])
def main_display(stdscr): cursor_y = 1 editing = False k = 0 scheduler = win32com.client.Dispatch('Schedule.Service') curses.curs_set(0) stdscr.clear() stdscr.refresh() height, width = stdscr.getmaxyx() curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK) global x_pos_cService global x_pos_cServTime global x_pos_hours global x_pos_minutes global x_pos_seconds title_str = "Adjust Sunday Service" label_service_day = "Current Service Day: " label_service_times = "Current Service Times: " label_length = "Service Length: " label_hours = "Hours: " label_minutes = "Minutes: " label_seconds = "Seconds: " status_msg_1 = " Press (e) to edit " status_msg_2 = " Press (tab) to go to next input | Press (s) to save " status_msg_3 = " Press (return) to Change Times | Press (tab) to go to next input | Press (s) to save " success = "" if not temp_current == "": current_service = temp_current else: current_service = get_current_service(scheduler) if not temp_nine == 0: if temp_nine == True: current_service_times = current_service_times + "9am" if temp_eleven == True: if len(current_service_times) == 0: current_service_times = current_service_times + "11am" else: current_service_times = current_service_times + ", 11am" if temp_one == True: if len(current_service_times) == 0: current_service_times = current_service_times + "1pm" else: current_service_times = current_service_times + ", 1pm" if temp_three == True: if len(current_service_times) == 0: current_service_times = current_service_times + "3pm" else: current_service_times = current_service_times + ", 3pm" if temp_five == True: if len(current_service_times) == 0: current_service_times = current_service_times + "5pm" else: current_service_times = current_service_times + ", 5pm" if temp_six == True: if len(current_service_times) == 0: current_service_times = current_service_times + "7pm" else: current_service_times = current_service_times + ", 7pm" else: current_service_times = get_current_serv_times(scheduler) x_pos_cService = len(label_service_day) + 2 x_pos_cServTime = len(label_service_times) + 2 x_pos_hours = len(label_hours) + 2 x_pos_minutes = len(label_minutes) + 2 x_pos_seconds = len(label_seconds) + 2 if not temp_hour == 0: hours = temp_hour minutes = temp_minute seconds = temp_seconds else: hours, minutes, seconds = get_length_time() isError = False while (True): stdscr.clear() m.title(stdscr, title_str) if editing == False: cursor_x = 1 curses.curs_set(0) m.status_bar(stdscr, status_msg_1) m.add_label(stdscr, label_service_day, 1, 1) m.add_solid(stdscr, current_service, 1, x_pos_cService, cursor_y) m.add_label(stdscr, label_service_times, 2, 1) m.add_solid(stdscr, current_service_times, 2, x_pos_cServTime, cursor_y) m.add_label(stdscr, label_length, 3, 1) m.add_label(stdscr, label_hours, 4, 1) m.add_solid(stdscr, hours, 4, x_pos_hours, cursor_y) m.add_label(stdscr, label_minutes, 5, 1) m.add_solid(stdscr, minutes, 5, x_pos_minutes, cursor_y) m.add_label(stdscr, label_seconds, 6, 1) m.add_solid(stdscr, seconds, 6, x_pos_seconds, cursor_y) else: if not cursor_y == 2: curses.curs_set(1) if cursor_y == 1: m.status_bar(stdscr, status_msg_2) else: m.status_bar(stdscr, status_msg_3) if isError == True: cursor_y = 1 m.input_option(stdscr, label_service_day, 1, 1, cursor_y, True) else: m.input_option(stdscr, label_service_day, 1, 1, cursor_y, False) m.add_label(stdscr, label_service_times, 2, 1) m.add_label(stdscr, label_length, 3, 1) m.input_option(stdscr, label_hours, 4, 1, cursor_y, False) m.input_option(stdscr, label_minutes, 5, 1, cursor_y, False) m.input_option(stdscr, label_seconds, 6, 1, cursor_y, False) m.add_string(stdscr, current_service, 1, x_pos_cService) m.add_solid(stdscr, current_service_times, 2, x_pos_cServTime, cursor_y) m.add_string(stdscr, hours, 4, x_pos_hours) m.add_string(stdscr, minutes, 5, x_pos_minutes) m.add_string(stdscr, seconds, 6, x_pos_seconds) m.status(stdscr, isError, success, 4, curses.color_pair(2), curses.color_pair(4)) stdscr.move(cursor_y, cursor_x) stdscr.refresh() k = stdscr.getch() if k == 27: sc.start() elif k == curses.KEY_UP: cursor_y -= 1 if cursor_y == 0: cursor_y = 6 elif cursor_y == 3: cursor_y = 2 cursor_x = move_x(cursor_y) elif k == curses.KEY_DOWN: cursor_y += 1 if cursor_y == 3: cursor_y = 4 elif cursor_y == 7: cursor_y = 1 cursor_x = move_x(cursor_y) elif k == ord('e') and editing == False: editing = True cursor_x = move_x(cursor_y) elif k == ord('s') and editing == True: pass elif k == 9 and editing == True: if cursor_y == 1: cursor_y = 2 elif cursor_y == 2: cursor_y = 3 time_spot = 1 elif cursor_y == 3: if time_spot == 1: time_spot = 2 elif time_spot == 2: time_spot = 3 elif time_spot == 3: time_spot = 1 cursor_y = 1 elif k == 10 and editing == True and cursor_y == 2: global temp_hour global temp_minute global temp_second global temp_current temp_hour = hours temp_minute = minutes temp_second = seconds temp_current = current_service curses.wrapper(get_service_times) elif editing == True and k == curses.KEY_LEFT: if cursor_y == 1 and not cursor_x <= x_pos_cService: cursor_x -= 1 str_pos = cursor_x - x_pos_cService if str_pos == 2 or str_pos == 5: cursor_x -= 1 elif cursor_y == 4 and not cursor_x <= x_pos_hours: cursor_x -= 1 elif cursor_y == 5 and not cursor_x <= x_pos_minutes: cursor_x -= 1 elif cursor_y == 6 and not cursor_x <= x_pos_hours: cursor_x -= 1 elif editing == True and k == curses.KEY_RIGHT: if cursor_y == 1 and not cursor_x >= x_pos_cService + len( current_service): cursor_x += 1 str_pos = cursor_x - x_pos_cService if str_pos == 2 or str_pos == 5: cursor_x += 1 elif cursor_y == 4 and not cursor_x >= x_pos_hours + len(hours): cursor_x += 1 elif cursor_y == 5 and not cursor_x >= x_pos_minutes + len(minutes): cursor_x += 1 elif cursor_y == 6 and not cursor_x >= x_pos_seconds + len(seconds): cursor_x += 1 elif editing == True: if cursor_y == 1: current_service = m.inputs(current_service, k, x_pos_cService, cursor_x) cursor_x += 1 str_pos = (cursor_x - x_pos_cService) if str_pos == 2 or str_pos == 5: cursor_x += 1 if cursor_x == len(current_service) + x_pos_cService: cursor_y = 2 cursor_x = move_x(cursor_y) elif cursor_y == 4: hours = m.inputs(hours, k, x_pos_hours, cursor_x) cursor_x += 1 str_pos = (cursor_x - x_pos_hours) if str_pos == 2: cursor_y = 5 cursor_x = move_x(cursor_y) elif cursor_y == 5: minutes = m.inputs(minutes, k, x_pos_minutes, cursor_x) cursor_x += 1 str_pos = (cursor_x - x_pos_minutes) if str_pos == 2: cursor_y = 6 cursor_x = move_x(cursor_y) elif cursor_y == 6: seconds = m.inputs(seconds, k, x_pos_seconds, cursor_x) cursor_x += 1 str_pos = cursor_x - x_pos_seconds if str_pos == 2: cursor_y = 1 cursor_x = move_x(cursor_y)
def tab_test(): scheduler.start(jobs, daemon=False)