Skip to content

Commit 1a2b2f1

Browse files
authored
Add support for newly added QStash features (#41)
There were lots of new features missing from the client, I have added support for them. Also, refactored some leftover parts.
1 parent 5c64d9b commit 1a2b2f1

29 files changed

+663
-370
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
4141
- name: Run mypy
4242
run: |
43-
poetry run mypy --show-error-codes .
43+
poetry run mypy --show-error-codes --strict .
4444
4545
- name: Run tests
4646
run: |

examples/async_publish.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from qstash import AsyncQStash
88

99

10-
async def main():
10+
async def main() -> None:
1111
client = AsyncQStash(
1212
token="<QSTASH-TOKEN>",
1313
)
@@ -21,7 +21,7 @@ async def main():
2121
delay="3s",
2222
)
2323

24-
print(res.message_id)
24+
print(res.message_id) # type:ignore[union-attr]
2525

2626

2727
if __name__ == "__main__":

examples/basic_publish.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from qstash import QStash
66

77

8-
def main():
8+
def main() -> None:
99
client = QStash(
1010
token="<QSTASH-TOKEN>",
1111
)
@@ -19,7 +19,7 @@ def main():
1919
delay="3s",
2020
)
2121

22-
print(res.message_id)
22+
print(res.message_id) # type:ignore[union-attr]
2323

2424

2525
if __name__ == "__main__":

examples/basic_schedule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from qstash import QStash
66

77

8-
def main():
8+
def main() -> None:
99
client = QStash(
1010
token="<QSTASH-TOKEN>",
1111
)

examples/callback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from qstash import QStash
1010

1111

12-
def main():
12+
def main() -> None:
1313
client = QStash(
1414
token="<QSTASH-TOKEN>",
1515
)

examples/llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from qstash.chat import openai
1010

1111

12-
def main():
12+
def main() -> None:
1313
client = QStash(
1414
token="<QSTASH-TOKEN>",
1515
)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ classifiers = [
2121
"Programming Language :: Python :: 3.10",
2222
"Programming Language :: Python :: 3.11",
2323
"Programming Language :: Python :: 3.12",
24+
"Programming Language :: Python :: 3.13",
2425
"Programming Language :: Python :: Implementation :: CPython",
2526
"Topic :: Database",
2627
"Topic :: Database :: Front-Ends",
@@ -39,7 +40,7 @@ pytest = "^8.2.2"
3940
python-dotenv = "^1.0.1"
4041
pytest-asyncio = "^0.23.7"
4142
mypy = "^1.10.0"
42-
ruff = "^0.5.0"
43+
ruff = "^0.11.7"
4344

4445
[build-system]
4546
requires = ["poetry-core"]

qstash/asyncio/dlq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ async def delete_many(self, dlq_ids: List[str]) -> int:
9090
body=body,
9191
)
9292

93-
return response["deleted"]
93+
return response["deleted"] # type:ignore[no-any-return]

qstash/asyncio/log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from qstash.asyncio.http import AsyncHttpClient
44
from qstash.log import (
5-
EventFilter,
5+
LogFilter,
66
ListLogsResponse,
77
parse_logs_response,
88
prepare_list_logs_request_params,
@@ -18,7 +18,7 @@ async def list(
1818
*,
1919
cursor: Optional[str] = None,
2020
count: Optional[int] = None,
21-
filter: Optional[EventFilter] = None,
21+
filter: Optional[LogFilter] = None,
2222
) -> ListLogsResponse:
2323
"""
2424
Lists all logs that happened, such as message creation or delivery.

qstash/asyncio/message.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ async def publish(
4040
content_type: Optional[str] = None,
4141
method: Optional[HttpMethod] = None,
4242
headers: Optional[Dict[str, str]] = None,
43+
callback_headers: Optional[Dict[str, str]] = None,
44+
failure_callback_headers: Optional[Dict[str, str]] = None,
4345
retries: Optional[int] = None,
4446
callback: Optional[str] = None,
4547
failure_callback: Optional[str] = None,
@@ -67,6 +69,9 @@ async def publish(
6769
:param content_type: MIME type of the message.
6870
:param method: The HTTP method to use when sending a webhook to your API.
6971
:param headers: Headers to forward along with the message.
72+
:param callback_headers: Headers to forward along with the callback message.
73+
:param failure_callback_headers: Headers to forward along with the failure
74+
callback message.
7075
:param retries: How often should this message be retried in case the destination
7176
API is not available.
7277
:param callback: A callback url that will be called after each attempt.
@@ -86,8 +91,8 @@ async def publish(
8691
When a timeout is specified, it will be used instead of the maximum timeout
8792
value permitted by the QStash plan. It is useful in scenarios, where a message
8893
should be delivered with a shorter timeout.
89-
:param flow_control: Settings for controlling the number of active requests and
90-
number of requests per second with the same key.
94+
:param flow_control: Settings for controlling the number of active requests,
95+
as well as the rate of requests with the same flow control key.
9196
"""
9297
headers = headers or {}
9398
destination = get_destination(
@@ -101,6 +106,8 @@ async def publish(
101106
content_type=content_type,
102107
method=method,
103108
headers=headers,
109+
callback_headers=callback_headers,
110+
failure_callback_headers=failure_callback_headers,
104111
retries=retries,
105112
callback=callback,
106113
failure_callback=failure_callback,
@@ -130,6 +137,8 @@ async def publish_json(
130137
body: Optional[Any] = None,
131138
method: Optional[HttpMethod] = None,
132139
headers: Optional[Dict[str, str]] = None,
140+
callback_headers: Optional[Dict[str, str]] = None,
141+
failure_callback_headers: Optional[Dict[str, str]] = None,
133142
retries: Optional[int] = None,
134143
callback: Optional[str] = None,
135144
failure_callback: Optional[str] = None,
@@ -158,6 +167,9 @@ async def publish_json(
158167
serialized as JSON string.
159168
:param method: The HTTP method to use when sending a webhook to your API.
160169
:param headers: Headers to forward along with the message.
170+
:param callback_headers: Headers to forward along with the callback message.
171+
:param failure_callback_headers: Headers to forward along with the failure
172+
callback message.
161173
:param retries: How often should this message be retried in case the destination
162174
API is not available.
163175
:param callback: A callback url that will be called after each attempt.
@@ -177,8 +189,8 @@ async def publish_json(
177189
When a timeout is specified, it will be used instead of the maximum timeout
178190
value permitted by the QStash plan. It is useful in scenarios, where a message
179191
should be delivered with a shorter timeout.
180-
:param flow_control: Settings for controlling the number of active requests and
181-
number of requests per second with the same key.
192+
:param flow_control: Settings for controlling the number of active requests,
193+
as well as the rate of requests with the same flow control key.
182194
"""
183195
return await self.publish(
184196
url=url,
@@ -188,6 +200,8 @@ async def publish_json(
188200
content_type="application/json",
189201
method=method,
190202
headers=headers,
203+
callback_headers=callback_headers,
204+
failure_callback_headers=failure_callback_headers,
191205
retries=retries,
192206
callback=callback,
193207
failure_callback=failure_callback,
@@ -210,6 +224,8 @@ async def enqueue(
210224
content_type: Optional[str] = None,
211225
method: Optional[HttpMethod] = None,
212226
headers: Optional[Dict[str, str]] = None,
227+
callback_headers: Optional[Dict[str, str]] = None,
228+
failure_callback_headers: Optional[Dict[str, str]] = None,
213229
retries: Optional[int] = None,
214230
callback: Optional[str] = None,
215231
failure_callback: Optional[str] = None,
@@ -236,6 +252,9 @@ async def enqueue(
236252
:param content_type: MIME type of the message.
237253
:param method: The HTTP method to use when sending a webhook to your API.
238254
:param headers: Headers to forward along with the message.
255+
:param callback_headers: Headers to forward along with the callback message.
256+
:param failure_callback_headers: Headers to forward along with the failure
257+
callback message.
239258
:param retries: How often should this message be retried in case the destination
240259
API is not available.
241260
:param callback: A callback url that will be called after each attempt.
@@ -261,6 +280,8 @@ async def enqueue(
261280
content_type=content_type,
262281
method=method,
263282
headers=headers,
283+
callback_headers=callback_headers,
284+
failure_callback_headers=failure_callback_headers,
264285
retries=retries,
265286
callback=callback,
266287
failure_callback=failure_callback,
@@ -291,6 +312,8 @@ async def enqueue_json(
291312
body: Optional[Any] = None,
292313
method: Optional[HttpMethod] = None,
293314
headers: Optional[Dict[str, str]] = None,
315+
callback_headers: Optional[Dict[str, str]] = None,
316+
failure_callback_headers: Optional[Dict[str, str]] = None,
294317
retries: Optional[int] = None,
295318
callback: Optional[str] = None,
296319
failure_callback: Optional[str] = None,
@@ -318,6 +341,9 @@ async def enqueue_json(
318341
serialized as JSON string.
319342
:param method: The HTTP method to use when sending a webhook to your API.
320343
:param headers: Headers to forward along with the message.
344+
:param callback_headers: Headers to forward along with the callback message.
345+
:param failure_callback_headers: Headers to forward along with the failure
346+
callback message.
321347
:param retries: How often should this message be retried in case the destination
322348
API is not available.
323349
:param callback: A callback url that will be called after each attempt.
@@ -340,6 +366,8 @@ async def enqueue_json(
340366
content_type="application/json",
341367
method=method,
342368
headers=headers,
369+
callback_headers=callback_headers,
370+
failure_callback_headers=failure_callback_headers,
343371
retries=retries,
344372
callback=callback,
345373
failure_callback=failure_callback,
@@ -440,9 +468,9 @@ async def cancel_many(self, message_ids: List[str]) -> int:
440468
body=body,
441469
)
442470

443-
return response["cancelled"]
471+
return response["cancelled"] # type:ignore[no-any-return]
444472

445-
async def cancel_all(self):
473+
async def cancel_all(self) -> int:
446474
"""
447475
Cancels delivery of all the existing messages.
448476
@@ -457,4 +485,4 @@ async def cancel_all(self):
457485
method="DELETE",
458486
)
459487

460-
return response["cancelled"]
488+
return response["cancelled"] # type:ignore[no-any-return]

0 commit comments

Comments
 (0)