add pocketbase cron job
This commit is contained in:
parent
bf99b2949b
commit
10f138ac61
33
app/cron_pocketbase.py
Normal file
33
app/cron_pocketbase.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from datetime import datetime, timedelta
|
||||||
|
from pocketbase import PocketBase # Client also works the same
|
||||||
|
import asyncio
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
pb_admin_email = os.getenv('POCKETBASE_ADMIN_EMAIL')
|
||||||
|
pb_password = os.getenv('POCKETBASE_PASSWORD')
|
||||||
|
|
||||||
|
pb = PocketBase('http://127.0.0.1:8090')
|
||||||
|
admin_data = pb.admins.auth_with_password(pb_admin_email, pb_password)
|
||||||
|
|
||||||
|
|
||||||
|
now = datetime.now()
|
||||||
|
seven_days_ago = now - timedelta(days=7)
|
||||||
|
|
||||||
|
|
||||||
|
async def update_free_trial():
|
||||||
|
|
||||||
|
data = pb.collection("users").get_full_list(query_params = {"filter": f'freeTrial = True'})
|
||||||
|
|
||||||
|
for item in data:
|
||||||
|
created_date = item.created
|
||||||
|
# Check if the created date is more than 7 days ago
|
||||||
|
if created_date < seven_days_ago:
|
||||||
|
# Update the user record
|
||||||
|
pb.collection("users").update(item.id, {
|
||||||
|
"tier": 'Free',
|
||||||
|
"freeTrial": False,
|
||||||
|
})
|
||||||
|
|
||||||
|
asyncio.run(update_free_trial())
|
||||||
@ -33,6 +33,10 @@ def run_json_job():
|
|||||||
subprocess.run(["python3", "restart_json.py"])
|
subprocess.run(["python3", "restart_json.py"])
|
||||||
subprocess.run(["pm2", "restart","fastapi"])
|
subprocess.run(["pm2", "restart","fastapi"])
|
||||||
|
|
||||||
|
def run_pocketbase():
|
||||||
|
# Run the asynchronous function inside an asyncio loop
|
||||||
|
subprocess.run(["python3", "cron_pocketbase.py"])
|
||||||
|
|
||||||
def run_cron_insider_trading():
|
def run_cron_insider_trading():
|
||||||
week = datetime.today().weekday()
|
week = datetime.today().weekday()
|
||||||
if week <= 5:
|
if week <= 5:
|
||||||
@ -316,6 +320,8 @@ schedule.every().day.at("01:00").do(run_threaded, run_options_bubble_ticker).tag
|
|||||||
schedule.every().day.at("02:00").do(run_threaded, run_db_schedule_job)
|
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("03:00").do(run_threaded, run_dark_pool)
|
||||||
schedule.every().day.at("06:00").do(run_threaded, run_historical_price).tag('historical_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("07:00").do(run_threaded, run_ta_rating).tag('ta_rating_job')
|
||||||
schedule.every().day.at("08:00").do(run_threaded, run_cron_insider_trading).tag('insider_trading_job')
|
schedule.every().day.at("08:00").do(run_threaded, run_cron_insider_trading).tag('insider_trading_job')
|
||||||
schedule.every().day.at("09:00").do(run_threaded, run_congress_trading).tag('congress_job')
|
schedule.every().day.at("09:00").do(run_threaded, run_congress_trading).tag('congress_job')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user