From 936040fcb172f25a1b0f109f848db5530786d934 Mon Sep 17 00:00:00 2001 From: Beate Trenziok Date: Mon, 12 Aug 2024 10:42:43 +0200 Subject: [PATCH] Anpassung scheduler --- msp/hooks.py | 8 ++++++++ msp/tools.py | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/msp/hooks.py b/msp/hooks.py index ad1895b..8b9d190 100644 --- a/msp/hooks.py +++ b/msp/hooks.py @@ -108,6 +108,14 @@ doc_events = { # Scheduled Tasks # --------------- +scheduler_events = { + "cron": { + "*/5 * * * *": [ + "msp.tools.update_tickets_and_articles" + ] + } +} + # scheduler_events = { # "all": [ # "msp.tasks.all" diff --git a/msp/tools.py b/msp/tools.py index d31d321..b6d6137 100644 --- a/msp/tools.py +++ b/msp/tools.py @@ -435,10 +435,15 @@ def update_tickets_and_articles(): # Ensure settings.last_ticket_sync has a default value 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)}") 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)) articles = get_articles_from_otrsdb(otrsdb, int(settings.last_article_id)) print(len(articles))