Answer the question
In order to leave comments, you need to log in
Just in 15 minutes to update values in a DB?
I have a database with payments. And I need to do something like this every 15 times -
if the COMPLETED == false column and the CANCELED == false column, set the value of the CANCELED == true column
Answer the question
In order to leave comments, you need to log in
Do you want to make a late payment?
Write a simple demon.
Add the created field to the database, where, when creating a payment, write down the current unixtime.
import time
t = int(time.time())
print(t)
import time
import pymysql
while True:
connect = pymysql.connect(host='127.0.0.1', user='root', password='228', db='database_name')
cursor = connect.cursor()
cursor.execute(f"UPDATE payments SET CANCELED=1 WHERE CANCELED=0 AND COMPLETED=0 AND created<{time.time() - 60 * 15}")
connect.commit()
connect.close()
time.sleep(60)
It seems to me that you are mistaken with the logic and you need to do this more than once every 15 minutes, otherwise what will happen if your event occurs a second before the end of this 15-minute interval? Those. to complete the task (which you cancel) you will have not 15 minutes but a second.
If you need to count some time from the moment of the event, then you need to store in the database the beginning of the time from which the countdown begins, then the interval end condition will be now-start_time>interval_duration, make such a finished field calculated in the view or immediately in your request.
You can create several such fields.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question