import threading | |
import psycopg2 | |
def updater(): | |
connection = psycopg2.connect('dbname=crontabber_exampleapp') | |
cursor = connection.cursor() | |
cursor.execute(""" | |
SELECT ongoing FROM crontabber WHERE app_name = 'bar' | |
FOR UPDATE NOWAIT | |
""") | |
cursor.execute(""" | |
UPDATE crontabber SET ongoing = now() WHERE app_name = 'bar' | |
""") | |
print("JOB CAN START!") | |
connection.commit() | |
# Use threads to simulate starting two connections virtually | |
# simultaneously. | |
threads = [ | |
threading.Thread(target=updater), | |
threading.Thread(target=updater), | |
] | |
for thread in threads: | |
thread.start() | |
for thread in threads: | |
thread.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment