Skip to content

Commit

Permalink
feat: add ending_at property to Schedule (#38)
Browse files Browse the repository at this point in the history
* feat: add ending_at property to schedule creation and update

Co-Authored-By: Christopher Bell <chris@knock.app>

* chore: bump version to 0.5.12

Co-Authored-By: Christopher Bell <chris@knock.app>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Christopher Bell <chris@knock.app>
  • Loading branch information
devin-ai-integration[bot] and cjbell authored Jan 28, 2025
1 parent 247dd45 commit 4f2d1fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
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

0 comments on commit 4f2d1fb

Please sign in to comment.