From eedd287c71c4cf76b4da712cde9e1e0477d971f7 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Thu, 19 Sep 2024 22:49:58 +0200 Subject: [PATCH] migrate pb task to secondary_cron --- app/primary_cron_job.py | 12 +----------- app/secondary_cron_job.py | 7 +++++++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/primary_cron_job.py b/app/primary_cron_job.py index 0529668..90506a5 100755 --- a/app/primary_cron_job.py +++ b/app/primary_cron_job.py @@ -56,15 +56,7 @@ def run_command(command): if stderr: logger.error("Error:\n" + stderr) -def run_json(): - # Run the asynchronous function inside an asyncio loop - run_command(["python3", "restart_json.py"]) - run_command(["pm2", "restart","fastapi"]) - run_command(["pm2", "restart","fastify"]) -def run_pocketbase(): - # Run the asynchronous function inside an asyncio loop - run_command(["python3", "cron_pocketbase.py"]) def run_cron_insider_trading(): week = datetime.today().weekday() @@ -593,7 +585,6 @@ schedule.every().day.at("02:00").do(run_threaded, run_db_schedule_job) schedule.every().day.at("03:00").do(run_threaded, run_dark_pool) schedule.every().day.at("05:00").do(run_threaded, run_options_gex).tag('options_gex_job') schedule.every().day.at("06:00").do(run_threaded, run_historical_price).tag('historical_job') -schedule.every().day.at("06:30").do(run_threaded, run_pocketbase).tag('pocketbase_job') schedule.every().day.at("07:00").do(run_threaded, run_ta_rating).tag('ta_rating_job') schedule.every().day.at("09:00").do(run_threaded, run_hedge_fund).tag('hedge_fund_job') @@ -619,7 +610,7 @@ schedule.every().day.at("13:45").do(run_threaded, run_similar_stocks).tag('simil schedule.every().day.at("14:00").do(run_threaded, run_cron_var).tag('var_job') schedule.every().day.at("14:00").do(run_threaded, run_cron_sector).tag('sector_job') -schedule.every().day.at("15:45").do(run_threaded, run_restart_cache) +#schedule.every().day.at("15:45").do(run_threaded, run_restart_cache) schedule.every(2).days.at("01:00").do(run_threaded, run_market_maker).tag('markt_maker_job') schedule.every(2).days.at("08:30").do(run_threaded, run_financial_score).tag('financial_score_job') @@ -648,7 +639,6 @@ schedule.every(30).minutes.do(run_threaded, run_earnings).tag('earnings_job') schedule.every(2).hours.do(run_threaded, run_fda_calendar).tag('fda_calendar_job') schedule.every(3).hours.do(run_threaded, run_options_net_flow).tag('options_net_flow_job') -schedule.every(6).hours.do(run_threaded, run_json).tag('json_job') #schedule.every(4).hours.do(run_threaded, run_share_statistics).tag('share_statistics_job') #schedule.every(2).days.at("01:00").do(run_borrowed_share).tag('borrowed_share_job') diff --git a/app/secondary_cron_job.py b/app/secondary_cron_job.py index 18c76f6..ded8449 100755 --- a/app/secondary_cron_job.py +++ b/app/secondary_cron_job.py @@ -21,6 +21,11 @@ berlin_tz = pytz.timezone('Europe/Berlin') # Set the system's timezone to Berlin at the beginning subprocess.run(["timedatectl", "set-timezone", "Europe/Berlin"]) + +def run_pocketbase(): + # Run the asynchronous function inside an asyncio loop + run_command(["python3", "cron_pocketbase.py"]) + def run_restart_cache(): #update db daily week = datetime.today().weekday() @@ -36,12 +41,14 @@ def run_json_job(): subprocess.run(["pm2", "restart","fastify"]) + # Create functions to run each schedule in a separate thread def run_threaded(job_func): job_thread = threading.Thread(target=job_func) job_thread.start() +schedule.every().day.at("06:30").do(run_threaded, run_pocketbase).tag('pocketbase_job') schedule.every().day.at("15:45").do(run_threaded, run_restart_cache) schedule.every(2).hours.do(run_threaded, run_json_job).tag('json_job')