Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions knockapi/resources/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def create_schedules(
scheduled_at=None,
data={},
actor=None,
tenant=None):
tenant=None,
ending_at=None):
"""
Creates schedules for recipients.

Expand All @@ -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
"""
Expand All @@ -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(
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Loading