Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schedule_id Parameter to create/create_json Methods #31

Merged
merged 1 commit into from
Dec 6, 2024
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
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
Loading