From cd82ade8e28dbb3190dbf06af88de28b377d6529 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari <74908943+Hrishabh17@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:01:06 +0530 Subject: [PATCH] fix: add unique constraint in task_logs for expense_group, add interval for next run (#408) --- .../0010_alter_tasklog_expense_group.py | 20 +++++++++++++++++++ apps/tasks/models.py | 1 + apps/workspaces/queue.py | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 apps/tasks/migrations/0010_alter_tasklog_expense_group.py diff --git a/apps/tasks/migrations/0010_alter_tasklog_expense_group.py b/apps/tasks/migrations/0010_alter_tasklog_expense_group.py new file mode 100644 index 00000000..d6e78955 --- /dev/null +++ b/apps/tasks/migrations/0010_alter_tasklog_expense_group.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.14 on 2024-11-14 10:37 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('fyle', '0020_expensegroup_export_url'), + ('tasks', '0009_error_repetition_count'), + ] + + operations = [ + migrations.AlterField( + model_name='tasklog', + name='expense_group', + field=models.ForeignKey(help_text='Reference to Expense group', null=True, on_delete=django.db.models.deletion.PROTECT, to='fyle.expensegroup', unique=True), + ), + ] diff --git a/apps/tasks/models.py b/apps/tasks/models.py index 04732c5a..a744d474 100644 --- a/apps/tasks/models.py +++ b/apps/tasks/models.py @@ -32,6 +32,7 @@ class TaskLog(models.Model): on_delete=models.PROTECT, null=True, help_text="Reference to Expense group", + unique=True ) payment = models.ForeignKey( Payment, on_delete=models.PROTECT, help_text="Reference to Payment", null=True diff --git a/apps/workspaces/queue.py b/apps/workspaces/queue.py index d8716e90..3908c3d3 100644 --- a/apps/workspaces/queue.py +++ b/apps/workspaces/queue.py @@ -57,7 +57,7 @@ def schedule_sync( defaults={ "schedule_type": Schedule.MINUTES, "minutes": hours * 60, - "next_run": datetime.now(), + "next_run": datetime.now() + timedelta(hours=hours), } )