Skip to content

IhaveDebt/SQL-Event-Scheduling-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

scheduler.py

import psycopg2 import time

DB_PARAMS = { "dbname": "scheduler_db", "user": "postgres", "password": "password", "host": "localhost", "port": 5432 }

def run_scheduler(): conn = psycopg2.connect(**DB_PARAMS) cur = conn.cursor() while True: cur.execute(""" SELECT id, task_name FROM events WHERE scheduled_time <= now() AND executed = false; """) tasks = cur.fetchall() for t in tasks: print(f"Executing task: {t[1]}") cur.execute("UPDATE events SET executed = true WHERE id = %s;", (t[0],)) conn.commit() time.sleep(5)

if name == "main": run_scheduler()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published