Skip to content

Commit

Permalink
Merge pull request #31 from upstash/DX-1462
Browse files Browse the repository at this point in the history
Add schedule_id Parameter to create/create_json Methods
  • Loading branch information
CahidArda authored Dec 6, 2024
2 parents f5aa0e3 + 10842f5 commit 47cc88f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions qstash/asyncio/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def create(
failure_callback: Optional[str] = None,
delay: Optional[Union[str, int]] = None,
timeout: Optional[Union[str, int]] = None,
schedule_id: Optional[str] = None,
) -> str:
"""
Creates a schedule to send messages periodically.
Expand All @@ -54,6 +55,7 @@ async def create(
When a timeout is specified, it will be used instead of the maximum timeout
value permitted by the QStash plan. It is useful in scenarios, where a message
should be delivered with a shorter timeout.
:param schedule_id: Schedule id to use. Can be used to update the settings of an existing schedule.
"""
req_headers = prepare_schedule_headers(
cron=cron,
Expand All @@ -65,6 +67,7 @@ async def create(
failure_callback=failure_callback,
delay=delay,
timeout=timeout,
schedule_id=schedule_id,
)

response = await self._http.request(
Expand All @@ -89,6 +92,7 @@ async def create_json(
failure_callback: Optional[str] = None,
delay: Optional[Union[str, int]] = None,
timeout: Optional[Union[str, int]] = None,
schedule_id: Optional[str] = None,
) -> str:
"""
Creates a schedule to send messages periodically, automatically serializing the
Expand Down Expand Up @@ -116,6 +120,7 @@ async def create_json(
When a timeout is specified, it will be used instead of the maximum timeout
value permitted by the QStash plan. It is useful in scenarios, where a message
should be delivered with a shorter timeout.
:param schedule_id: Schedule id to use. Can be used to update the settings of an existing schedule.
"""
return await self.create(
destination=destination,
Expand All @@ -128,6 +133,8 @@ async def create_json(
callback=callback,
failure_callback=failure_callback,
delay=delay,
timeout=timeout,
schedule_id=schedule_id,
)

async def get(self, schedule_id: str) -> Schedule:
Expand Down
10 changes: 10 additions & 0 deletions qstash/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def prepare_schedule_headers(
failure_callback: Optional[str],
delay: Optional[Union[str, int]],
timeout: Optional[Union[str, int]],
schedule_id: Optional[str],
) -> Dict[str, str]:
h = {
"Upstash-Cron": cron,
Expand Down Expand Up @@ -104,6 +105,9 @@ def prepare_schedule_headers(
else:
h["Upstash-Timeout"] = timeout

if schedule_id is not None:
h["Upstash-Schedule-Id"] = schedule_id

return h


Expand Down Expand Up @@ -144,6 +148,7 @@ def create(
failure_callback: Optional[str] = None,
delay: Optional[Union[str, int]] = None,
timeout: Optional[Union[str, int]] = None,
schedule_id: Optional[str] = None,
) -> str:
"""
Creates a schedule to send messages periodically.
Expand All @@ -170,6 +175,7 @@ def create(
When a timeout is specified, it will be used instead of the maximum timeout
value permitted by the QStash plan. It is useful in scenarios, where a message
should be delivered with a shorter timeout.
:param schedule_id: Schedule id to use. Can be used to update the settings of an existing schedule.
"""
req_headers = prepare_schedule_headers(
cron=cron,
Expand All @@ -181,6 +187,7 @@ def create(
failure_callback=failure_callback,
delay=delay,
timeout=timeout,
schedule_id=schedule_id,
)

response = self._http.request(
Expand All @@ -205,6 +212,7 @@ def create_json(
failure_callback: Optional[str] = None,
delay: Optional[Union[str, int]] = None,
timeout: Optional[Union[str, int]] = None,
schedule_id: Optional[str] = None,
) -> str:
"""
Creates a schedule to send messages periodically, automatically serializing the
Expand Down Expand Up @@ -232,6 +240,7 @@ def create_json(
When a timeout is specified, it will be used instead of the maximum timeout
value permitted by the QStash plan. It is useful in scenarios, where a message
should be delivered with a shorter timeout.
:param schedule_id: Schedule id to use. Can be used to update the settings of an existing schedule.
"""
return self.create(
destination=destination,
Expand All @@ -245,6 +254,7 @@ def create_json(
failure_callback=failure_callback,
delay=delay,
timeout=timeout,
schedule_id=schedule_id,
)

def get(self, schedule_id: str) -> Schedule:
Expand Down

0 comments on commit 47cc88f

Please sign in to comment.