Anpassung scheduler

This commit is contained in:
Beate Trenziok 2024-08-12 10:42:43 +02:00
parent 8679e44386
commit 936040fcb1
2 changed files with 14 additions and 1 deletions

View File

@ -108,6 +108,14 @@ doc_events = {
# Scheduled Tasks # Scheduled Tasks
# --------------- # ---------------
scheduler_events = {
"cron": {
"*/5 * * * *": [
"msp.tools.update_tickets_and_articles"
]
}
}
# scheduler_events = { # scheduler_events = {
# "all": [ # "all": [
# "msp.tasks.all" # "msp.tasks.all"

View File

@ -435,10 +435,15 @@ def update_tickets_and_articles():
# Ensure settings.last_ticket_sync has a default value # Ensure settings.last_ticket_sync has a default value
last_ticket_sync = settings.last_ticket_sync or '2024-07-01T00:00:00' last_ticket_sync = settings.last_ticket_sync or '2024-07-01T00:00:00'
# Add a buffer of 15 minutes to the last_ticket_sync time
last_ticket_sync_time = datetime.strptime(last_ticket_sync, "%Y-%m-%d %H:%M:%S")
last_ticket_sync_with_buffer = (last_ticket_sync_time - timedelta(minutes=15)).strftime("%Y-%m-%d %H:%M:%S")
new_tickets = get_tickets_from_otrsdb(otrsdb, f"ticket.id > {int(settings.last_ticket_id)}") new_tickets = get_tickets_from_otrsdb(otrsdb, f"ticket.id > {int(settings.last_ticket_id)}")
print(len(new_tickets)) print(len(new_tickets))
updated_tickets = get_tickets_from_otrsdb(otrsdb, f"ticket.change_time > '{last_ticket_sync}'") updated_tickets = get_tickets_from_otrsdb(otrsdb, f"ticket.change_time > '{last_ticket_sync_with_buffer}'")
print(len(updated_tickets)) print(len(updated_tickets))
articles = get_articles_from_otrsdb(otrsdb, int(settings.last_article_id)) articles = get_articles_from_otrsdb(otrsdb, int(settings.last_article_id))
print(len(articles)) print(len(articles))