add pocketbase cron job

This commit is contained in:
MuslemRahimi 2024-06-21 12:29:59 +02:00
parent bf99b2949b
commit 10f138ac61
2 changed files with 39 additions and 0 deletions

33
app/cron_pocketbase.py Normal file
View 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())

View File

@ -33,6 +33,10 @@ def run_json_job():
subprocess.run(["python3", "restart_json.py"])
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():
week = datetime.today().weekday()
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("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: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("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')