mirror of
https://github.com/simon987/od-database.git
synced 2025-04-20 02:46:45 +00:00
Create new rescan task when no queued tasks
This commit is contained in:
parent
2ef60a05a5
commit
1d3318f6e2
12
app.py
12
app.py
@ -550,9 +550,17 @@ def api_get_task():
|
||||
|
||||
if task:
|
||||
print("Assigning task " + str(task.website_id) + " to " + name)
|
||||
return Response(str(task), mimetype="application/json")
|
||||
else:
|
||||
return abort(404)
|
||||
print("No queued tasks, creating new rescan task")
|
||||
|
||||
website_id = db.get_oldest_website_id()
|
||||
website = db.get_website_by_id(website_id)
|
||||
task = Task(website_id, website.url)
|
||||
db.put_task(task)
|
||||
|
||||
task = db.pop_task(name)
|
||||
|
||||
return Response(str(task), mimetype="application/json")
|
||||
else:
|
||||
return abort(403)
|
||||
|
||||
|
@ -156,14 +156,13 @@ class Database:
|
||||
website_id = cursor.fetchone()
|
||||
return website_id[0] if website_id else None
|
||||
|
||||
def get_websites_older(self, delta: datetime.timedelta):
|
||||
"""Get websites last updated before a given date"""
|
||||
date = datetime.datetime.utcnow() - delta
|
||||
def get_oldest_website_id(self):
|
||||
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT Website.id FROM Website WHERE last_modified < ?", (date, ))
|
||||
return [x[0] for x in cursor.fetchall()]
|
||||
cursor.execute("SELECT Website.id FROM Website WHERE Website.id not in (SELECT website_id FROM Queue) "
|
||||
"ORDER BY last_modified ASC LIMIT 1")
|
||||
return cursor.fetchone()[0]
|
||||
|
||||
def delete_website(self, website_id):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user