mirror of
https://github.com/simon987/od-database.git
synced 2025-04-19 18:36:44 +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:
|
if task:
|
||||||
print("Assigning task " + str(task.website_id) + " to " + name)
|
print("Assigning task " + str(task.website_id) + " to " + name)
|
||||||
return Response(str(task), mimetype="application/json")
|
|
||||||
else:
|
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:
|
else:
|
||||||
return abort(403)
|
return abort(403)
|
||||||
|
|
||||||
|
@ -156,14 +156,13 @@ class Database:
|
|||||||
website_id = cursor.fetchone()
|
website_id = cursor.fetchone()
|
||||||
return website_id[0] if website_id else None
|
return website_id[0] if website_id else None
|
||||||
|
|
||||||
def get_websites_older(self, delta: datetime.timedelta):
|
def get_oldest_website_id(self):
|
||||||
"""Get websites last updated before a given date"""
|
|
||||||
date = datetime.datetime.utcnow() - delta
|
|
||||||
|
|
||||||
with sqlite3.connect(self.db_path) as conn:
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("SELECT Website.id FROM Website WHERE last_modified < ?", (date, ))
|
cursor.execute("SELECT Website.id FROM Website WHERE Website.id not in (SELECT website_id FROM Queue) "
|
||||||
return [x[0] for x in cursor.fetchall()]
|
"ORDER BY last_modified ASC LIMIT 1")
|
||||||
|
return cursor.fetchone()[0]
|
||||||
|
|
||||||
def delete_website(self, website_id):
|
def delete_website(self, website_id):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user