Skip to content

Commit

Permalink
Add explanation comment in new route
Browse files Browse the repository at this point in the history
Signed-off-by: angatupyry <fierrofenix@gmail.com>
  • Loading branch information
Angatupyry committed Sep 14, 2023
1 parent 4ba26f1 commit 9eb135a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/api-server/api_server/routes/tasks/scheduled_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,20 @@ async def update_schedule_task(
if task is None:
raise HTTPException(404)

if except_date:
task.except_dates.append(datetime_to_date_format(except_date))
await task.save()
# If except_date; single event: that event is deleted from the previous task, and a new one is created
# with the data requested in the schedule form [scheduled_task_request.schedules].
# Else; entire series: Task is completely deleted and another one is created
# with the changes requested by the user.
async with tortoise.transactions.in_transaction():
if except_date:
task.except_dates.append(datetime_to_date_format(except_date))
await task.save()

for sche in task.schedules:
schedule.clear(sche.get_id())
for sche in task.schedules:
schedule.clear(sche.get_id())

await schedule_task(task, task_repo)
await schedule_task(task, task_repo)

async with tortoise.transactions.in_transaction():
scheduled_task = await ttm.ScheduledTask.create(
task_request=scheduled_task_request.task_request.json(
exclude_none=True
Expand All @@ -197,8 +201,7 @@ async def update_schedule_task(
await ttm.ScheduledTaskSchedule.bulk_create(schedules)

await schedule_task(scheduled_task, task_repo)
else:
async with tortoise.transactions.in_transaction():
else:
task.update_from_dict(
{
"task_request": scheduled_task_request.task_request.json(
Expand Down

0 comments on commit 9eb135a

Please sign in to comment.