From 5831253435a039adb6b71496951d5dfa5d96f3c4 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 28 Jan 2025 02:14:22 +0000 Subject: [PATCH 1/2] feat: add ending_at property to schedule creation and update Co-Authored-By: Christopher Bell --- knockapi/resources/workflows.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/knockapi/resources/workflows.py b/knockapi/resources/workflows.py index 81b113e..eefe433 100644 --- a/knockapi/resources/workflows.py +++ b/knockapi/resources/workflows.py @@ -80,7 +80,8 @@ def create_schedules( scheduled_at=None, data={}, actor=None, - tenant=None): + tenant=None, + ending_at=None): """ Creates schedules for recipients. @@ -96,11 +97,14 @@ def create_schedules( data (dict): Any data to be passed to the scheduled trigger call. - scheduled_at (datetime): Date when the schedule must start + scheduled_at (datetime): Date when the schedule must start. tenant (str | dict[str, Any]): An optional reference for the tenant that the notifications belong to. This can be A) a tenant id, B) an object reference without the collection, or C) a dictionary with data to identify a tenant. + ending_at (datetime, optional): The date when the schedule should end. For recurring schedules, + no further executions will occur after this time. + Returns: list[dict]: list of created schedules """ @@ -112,10 +116,15 @@ def create_schedules( 'repeats': repeats, 'actor': actor, 'data': data, - 'tenant': tenant, - 'scheduled_at': scheduled_at.isoformat() + 'tenant': tenant } + if scheduled_at: + params['scheduled_at'] = scheduled_at.isoformat() + + if ending_at: + params['ending_at'] = ending_at.isoformat() + return self.client.request("post", endpoint, payload=params) def update_schedules( @@ -128,13 +137,22 @@ def update_schedules( Args: schedule_ids (list[str]): the ids of the schedules to be updated (max 100) - schedule_attrs (dict): Schedule attributes to be updated, these can be: repeats, actor, data and tenant. + schedule_attrs (dict): Schedule attributes to be updated. These can include: + - repeats: Schedule repeat configuration + - actor: Who/what performed the action + - data: Any data to be passed to the scheduled trigger + - tenant: The tenant that the notifications belong to + - ending_at (datetime): The date when the schedule should end Returns: list[dict]: list of updated schedules """ endpoint = '/schedules' + # Convert ending_at to ISO format if present + if 'ending_at' in schedule_attrs and schedule_attrs['ending_at']: + schedule_attrs['ending_at'] = schedule_attrs['ending_at'].isoformat() + schedule_attrs['schedule_ids'] = schedule_ids return self.client.request("put", endpoint, payload=schedule_attrs) From 5e3b053589bf9db829775b2fda11b0107b798364 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 28 Jan 2025 02:47:02 +0000 Subject: [PATCH 2/2] chore: bump version to 0.5.12 Co-Authored-By: Christopher Bell --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 71ff6ff..833cade 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import setuptools -version = '0.5.11' +version = '0.5.12' with open("README.md", "r") as f: long_description = f.read()