Skip to content

Commit 4f2d1fb

Browse files
feat: add ending_at property to Schedule (#38)
* feat: add ending_at property to schedule creation and update Co-Authored-By: Christopher Bell <[email protected]> * chore: bump version to 0.5.12 Co-Authored-By: Christopher Bell <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Christopher Bell <[email protected]>
1 parent 247dd45 commit 4f2d1fb

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

knockapi/resources/workflows.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def create_schedules(
8080
scheduled_at=None,
8181
data={},
8282
actor=None,
83-
tenant=None):
83+
tenant=None,
84+
ending_at=None):
8485
"""
8586
Creates schedules for recipients.
8687
@@ -96,11 +97,14 @@ def create_schedules(
9697
9798
data (dict): Any data to be passed to the scheduled trigger call.
9899
99-
scheduled_at (datetime): Date when the schedule must start
100+
scheduled_at (datetime): Date when the schedule must start.
100101
101102
tenant (str | dict[str, Any]): An optional reference for the tenant that the notifications belong to. This can be A) a tenant
102103
id, B) an object reference without the collection, or C) a dictionary with data to identify a tenant.
103104
105+
ending_at (datetime, optional): The date when the schedule should end. For recurring schedules,
106+
no further executions will occur after this time.
107+
104108
Returns:
105109
list[dict]: list of created schedules
106110
"""
@@ -112,10 +116,15 @@ def create_schedules(
112116
'repeats': repeats,
113117
'actor': actor,
114118
'data': data,
115-
'tenant': tenant,
116-
'scheduled_at': scheduled_at.isoformat()
119+
'tenant': tenant
117120
}
118121

122+
if scheduled_at:
123+
params['scheduled_at'] = scheduled_at.isoformat()
124+
125+
if ending_at:
126+
params['ending_at'] = ending_at.isoformat()
127+
119128
return self.client.request("post", endpoint, payload=params)
120129

121130
def update_schedules(
@@ -128,13 +137,22 @@ def update_schedules(
128137
Args:
129138
schedule_ids (list[str]): the ids of the schedules to be updated (max 100)
130139
131-
schedule_attrs (dict): Schedule attributes to be updated, these can be: repeats, actor, data and tenant.
140+
schedule_attrs (dict): Schedule attributes to be updated. These can include:
141+
- repeats: Schedule repeat configuration
142+
- actor: Who/what performed the action
143+
- data: Any data to be passed to the scheduled trigger
144+
- tenant: The tenant that the notifications belong to
145+
- ending_at (datetime): The date when the schedule should end
132146
133147
Returns:
134148
list[dict]: list of updated schedules
135149
"""
136150
endpoint = '/schedules'
137151

152+
# Convert ending_at to ISO format if present
153+
if 'ending_at' in schedule_attrs and schedule_attrs['ending_at']:
154+
schedule_attrs['ending_at'] = schedule_attrs['ending_at'].isoformat()
155+
138156
schedule_attrs['schedule_ids'] = schedule_ids
139157

140158
return self.client.request("put", endpoint, payload=schedule_attrs)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import setuptools
22

3-
version = '0.5.11'
3+
version = '0.5.12'
44

55
with open("README.md", "r") as f:
66
long_description = f.read()

0 commit comments

Comments
 (0)