def hlsWorker(): while True: schedule.every(10).seconds.do(regenKey) schedule.run_continuously() videos = db.getNewVideos() for video in videos: ndir = "".join( [rand.choice(ascii_letters + digits) for i in range(64)]) os.mkdir(cfg.HLS_VIDEOS_FOLDER + ndir) try: db.update_video(video[-1], cfg.HLS_VIDEOS_FOLDER + ndir, status="in_progress") mp4_to_HLS( cfg.SOURCE_VIDEOS_FOLDER + video[0] + ".mp4", cfg.HLS_VIDEOS_FOLDER + "%s/%s.m3u8" % (ndir, video[0])) db.update_video(video[-1], cfg.HLS_VIDEOS_FOLDER + ndir) except Exception as e: with open("log.log", 'a') as f: f.write(str(e)) continue schedule.clear() time.sleep(30)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.schedule_button = None self.scheduled = False self.work_time = 30 self.time_to_next_break = self.work_time self.schedule_button = None schedule.run_continuously()
def setup_app(): """Set up app with these configurations.""" if not app.config["TESTING"]: connect_to_db(app) # Use the DebugToolbar # DebugToolbarExtension(app) # At the same time every day (UTC time), do send_texts() schedule.every().day.at("23:00").do(send_texts) # Print statement for debugging/to see when setup_app() gets run print("start time:", datetime.now()) # Run continuously as opposed to schedule.run_pending() schedule.run_continuously()
def schedule_command(message): if message.chat.id != project_variables.HOST_ID: return command = message.text.split() if len(command) == 2: command = command[1].lower() if command == 'start': if utils.schedule_thread is None: schedule.every(NULLIFY_AFTER).minutes.do(nullify_spam_cnt) utils.init_schedule(schedule.run_continuously()) text = "Scheduler is running" elif command == 'stop': utils.stop_schedule_thread() schedule.clear() text = "Scheduler is stopped" else: text = "Wrong command" try: bot.send_message(project_variables.HOST_ID, text) except telebot.apihelper.ApiException: pass
@app.route("/listening", methods=["GET", "POST"]) def listening(): global pending data = json.loads(request.data) if "challenge" in data: return Response(data["challenge"], mimetype='application/json') if data["token"] != SLACK_VERIFICATION_TOKEN: return make_response("wrong token", 500) if data["event"]["type"] == "message": threading.Thread(target=message, args=[data["event"]]).start() elif data["event"]["type"] == "team_join": pending[data["event"]["user"]["id"]] = True save_pending() return make_response("", 200) @app.route("/slack/interactive", methods=["POST"]) def interactive(): data = json.loads(request.form["payload"]) threading.Thread(target=answer_callback, args=[data]).start() return make_response("", 200) if __name__ == "__main__": schedule.every(10).seconds.do(watchdog) schedule.run_continuously() parse_files() app.run(host='0.0.0.0', port=5050)
def run(self): self.set_schedules() schedule.run_continuously(interval=1) self.slackbot.send_message(text=MsgResource.WORKER_START)
def run_scheduled_tasks(): schedule.every(120).seconds.do(ws.refresh_token) # schedule.every(2).seconds.do(job) schedule.run_continuously()
def test_run_continuously(self): """Check that run_continuously() runs pending jobs. We do this by overriding datetime.datetime with mock objects that represent increasing system times. Please note that it is *intended behavior that run_continuously() does not run missed jobs*. For example, if you've registered a job that should run every minute and you set a continuous run interval of one hour then your job won't be run 60 times at each interval but only once. """ # Monkey-patch datetime.datetime to get predictable (=testable) results class MockDate(datetime.datetime): @classmethod def today(cls): return cls(2010, 1, 6) @classmethod def now(cls): return cls(2010, 1, 6, 12, 15, 0) original_datetime = datetime.datetime datetime.datetime = MockDate mock_job = make_mock_job() # Secondly Tests # Initialize everything. schedule.clear() mock_job.reset_mock() every().second.do(mock_job) # Start a new continuous run thread. stop_thread_flag = schedule.run_continuously(0) # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 0 # Secondly first second. class MockDate(datetime.datetime): @classmethod def today(cls): return cls(2010, 1, 6) @classmethod def now(cls): return cls(2010, 1, 6, 12, 15, 1) mock_job.reset_mock() datetime.datetime = MockDate # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 1 # Secondly second second. class MockDate(datetime.datetime): @classmethod def today(cls): return cls(2010, 1, 6) @classmethod def now(cls): return cls(2010, 1, 6, 12, 15, 2) datetime.datetime = MockDate # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 2 # Minutely Tests # (Re)Initialize everything. schedule.clear() mock_job.reset_mock() stop_thread_flag.set() every().minute.do(mock_job) # Start a new continuous run thread. stop_thread_flag = schedule.run_continuously(0) # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 0 # Minutely first minute. class MockDate(datetime.datetime): @classmethod def today(cls): return cls(2010, 1, 6) @classmethod def now(cls): return cls(2010, 1, 6, 12, 16, 2) mock_job.reset_mock() datetime.datetime = MockDate # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 1 # Minutely second minute. class MockDate(datetime.datetime): @classmethod def today(cls): return cls(2010, 1, 6) @classmethod def now(cls): return cls(2010, 1, 6, 12, 17, 2) datetime.datetime = MockDate # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 2 # Hourly Tests # (Re)Initialize everything. schedule.clear() mock_job.reset_mock() stop_thread_flag.set() every().hour.do(mock_job) # Start a new continuous run thread. stop_thread_flag = schedule.run_continuously(0) # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 0 # Hourly first hour. class MockDate(datetime.datetime): @classmethod def today(cls): return cls(2010, 1, 6) @classmethod def now(cls): return cls(2010, 1, 6, 13, 17, 2) mock_job.reset_mock() datetime.datetime = MockDate # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 1 # Hourly second hour. class MockDate(datetime.datetime): @classmethod def today(cls): return cls(2010, 1, 6) @classmethod def now(cls): return cls(2010, 1, 6, 14, 17, 2) datetime.datetime = MockDate # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 2 # Daily Tests # (Re)Initialize everything. schedule.clear() mock_job.reset_mock() stop_thread_flag.set() every().day.do(mock_job) # Start a new continuous run thread. stop_thread_flag = schedule.run_continuously(0) # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 0 # Daily first day. class MockDate(datetime.datetime): @classmethod def today(cls): return cls(2010, 1, 6) @classmethod def now(cls): return cls(2010, 1, 7, 14, 17, 2) mock_job.reset_mock() datetime.datetime = MockDate # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 1 # Daily second day. class MockDate(datetime.datetime): @classmethod def today(cls): return cls(2010, 1, 6) @classmethod def now(cls): return cls(2010, 1, 8, 14, 17, 2) datetime.datetime = MockDate # Allow a small time for separate thread to register time stamps. time.sleep(0.001) assert mock_job.call_count == 2 schedule.clear() mock_job.reset_mock() stop_thread_flag.set() datetime.datetime = original_datetime
global frontKeyCounter leftKeyCounter = 0 global backKeyCounter leftKeyCounter = 0 #print "left : %d , right : %d , front : %d , back : %d" % (leftKeyCounter, rightKeyCounter, frontKeyCounter, backKeyCounter) return (leftKeyCounter, rightKeyCounter, frontKeyCounter, backKeyCounter) print "back to 0" schedule.every(5).seconds.do(sendCommand) while True: schedule.run_continuously() readbuffer = readbuffer + s.recv(1024) temp = string.split(readbuffer, "\n") readbuffer = temp.pop() for line in temp: print(line) if "PING" in line: s.send(line.replace("PING", "PONG")) break user = getUser(line) message = getMessage(line) print user + " typed :" + message
x = x.text.strip() res.append(x) return res def send_daily_report(): try: mydb = mysql.connector.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASSWORD, database=DB_NAME) mycursor = mydb.cursor() mycursor.execute('SELECT * FROM user WHERE send=1') res = mycursor.fetchall() mycursor.close() mydb.close() for row in res: bot.send_message( row[0], '/stocks - get stock prices from KASE, NASDAQ and NYSE\n\ /news - get main news\n/weather - get current temperature\n/currency - get exchange rates\n\ /corona - get stats about COVID-19\n/recommend - get news recommendations') except: print('Cannot connect to DB') schedule.every().day.at("09:00").do(send_daily_report) schedule.run_continuously() #this method is added from FAQ (documentation) bot.polling()
def add_schedule_jobs(bot): # Declare sched event for adding days to database (window always of one week) schedule.every().day.at("00:05").do(update_slots) schedule.every().hour.at(":20").do(reminder, bot) schedule.every().hour.at(":50").do(reminder, bot) schedule.run_continuously() # for this to work I had to add code to