Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 3a05443

Browse files
macwilksrhinos
andauthored
Expose Default Priority In Workflow Creation (#157)
* Update SDK From Main * iSort Finally Ran * Priority SDK Updates * Expose Default Priority to SDK * Add In Value Validation + Reformatting * Dont Fail if Prio is None * Bump Version * Revert Branch Pin * Clean Up Example --------- Co-authored-by: srhinos <[email protected]>
1 parent 1c71e1a commit 3a05443

24 files changed

+2088
-699
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import asyncio
2+
from typing import TypedDict
3+
4+
from dotenv import load_dotenv
5+
6+
from hatchet_sdk import Context
7+
from hatchet_sdk.v2.hatchet import Hatchet
8+
9+
load_dotenv()
10+
11+
hatchet = Hatchet(debug=True)
12+
13+
14+
class MyResultType(TypedDict):
15+
return_string: str
16+
17+
18+
@hatchet.function(default_priority=2)
19+
async def high_prio_func(context: Context) -> MyResultType:
20+
await asyncio.sleep(5)
21+
return MyResultType(return_string="High Priority Return")
22+
23+
24+
@hatchet.function(default_priority=1)
25+
async def low_prio_func(context: Context) -> MyResultType:
26+
await asyncio.sleep(5)
27+
return MyResultType(return_string="Low Priority Return")
28+
29+
30+
def main():
31+
worker = hatchet.worker("example-priority-worker", max_runs=1)
32+
hatchet.admin.run(high_prio_func, {"test": "test"})
33+
hatchet.admin.run(high_prio_func, {"test": "test"})
34+
hatchet.admin.run(low_prio_func, {"test": "test"})
35+
hatchet.admin.run(low_prio_func, {"test": "test"})
36+
worker.start()
37+
38+
39+
if __name__ == "__main__":
40+
main()

hatchet_sdk/clients/rest/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@
188188
from hatchet_sdk.clients.rest.models.webhook_worker_list_response import (
189189
WebhookWorkerListResponse,
190190
)
191+
from hatchet_sdk.clients.rest.models.webhook_worker_request import WebhookWorkerRequest
192+
from hatchet_sdk.clients.rest.models.webhook_worker_request_list_response import (
193+
WebhookWorkerRequestListResponse,
194+
)
195+
from hatchet_sdk.clients.rest.models.webhook_worker_request_method import (
196+
WebhookWorkerRequestMethod,
197+
)
191198
from hatchet_sdk.clients.rest.models.worker import Worker
192199
from hatchet_sdk.clients.rest.models.worker_label import WorkerLabel
193200
from hatchet_sdk.clients.rest.models.worker_list import WorkerList

hatchet_sdk/clients/rest/api/default_api.py

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
from hatchet_sdk.clients.rest.models.webhook_worker_list_response import (
3131
WebhookWorkerListResponse,
3232
)
33+
from hatchet_sdk.clients.rest.models.webhook_worker_request_list_response import (
34+
WebhookWorkerRequestListResponse,
35+
)
3336
from hatchet_sdk.clients.rest.rest import RESTResponseType
3437

3538

@@ -1486,3 +1489,267 @@ def _webhook_list_serialize(
14861489
_host=_host,
14871490
_request_auth=_request_auth,
14881491
)
1492+
1493+
@validate_call
1494+
async def webhook_requests_list(
1495+
self,
1496+
webhook: Annotated[
1497+
str,
1498+
Field(
1499+
min_length=36, strict=True, max_length=36, description="The webhook id"
1500+
),
1501+
],
1502+
_request_timeout: Union[
1503+
None,
1504+
Annotated[StrictFloat, Field(gt=0)],
1505+
Tuple[
1506+
Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]
1507+
],
1508+
] = None,
1509+
_request_auth: Optional[Dict[StrictStr, Any]] = None,
1510+
_content_type: Optional[StrictStr] = None,
1511+
_headers: Optional[Dict[StrictStr, Any]] = None,
1512+
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
1513+
) -> WebhookWorkerRequestListResponse:
1514+
"""List webhook requests
1515+
1516+
Lists all requests for a webhook
1517+
1518+
:param webhook: The webhook id (required)
1519+
:type webhook: str
1520+
:param _request_timeout: timeout setting for this request. If one
1521+
number provided, it will be total request
1522+
timeout. It can also be a pair (tuple) of
1523+
(connection, read) timeouts.
1524+
:type _request_timeout: int, tuple(int, int), optional
1525+
:param _request_auth: set to override the auth_settings for an a single
1526+
request; this effectively ignores the
1527+
authentication in the spec for a single request.
1528+
:type _request_auth: dict, optional
1529+
:param _content_type: force content-type for the request.
1530+
:type _content_type: str, Optional
1531+
:param _headers: set to override the headers for a single
1532+
request; this effectively ignores the headers
1533+
in the spec for a single request.
1534+
:type _headers: dict, optional
1535+
:param _host_index: set to override the host_index for a single
1536+
request; this effectively ignores the host_index
1537+
in the spec for a single request.
1538+
:type _host_index: int, optional
1539+
:return: Returns the result object.
1540+
""" # noqa: E501
1541+
1542+
_param = self._webhook_requests_list_serialize(
1543+
webhook=webhook,
1544+
_request_auth=_request_auth,
1545+
_content_type=_content_type,
1546+
_headers=_headers,
1547+
_host_index=_host_index,
1548+
)
1549+
1550+
_response_types_map: Dict[str, Optional[str]] = {
1551+
"200": "WebhookWorkerRequestListResponse",
1552+
"400": "APIErrors",
1553+
"401": "APIErrors",
1554+
"405": "APIErrors",
1555+
}
1556+
response_data = await self.api_client.call_api(
1557+
*_param, _request_timeout=_request_timeout
1558+
)
1559+
await response_data.read()
1560+
return self.api_client.response_deserialize(
1561+
response_data=response_data,
1562+
response_types_map=_response_types_map,
1563+
).data
1564+
1565+
@validate_call
1566+
async def webhook_requests_list_with_http_info(
1567+
self,
1568+
webhook: Annotated[
1569+
str,
1570+
Field(
1571+
min_length=36, strict=True, max_length=36, description="The webhook id"
1572+
),
1573+
],
1574+
_request_timeout: Union[
1575+
None,
1576+
Annotated[StrictFloat, Field(gt=0)],
1577+
Tuple[
1578+
Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]
1579+
],
1580+
] = None,
1581+
_request_auth: Optional[Dict[StrictStr, Any]] = None,
1582+
_content_type: Optional[StrictStr] = None,
1583+
_headers: Optional[Dict[StrictStr, Any]] = None,
1584+
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
1585+
) -> ApiResponse[WebhookWorkerRequestListResponse]:
1586+
"""List webhook requests
1587+
1588+
Lists all requests for a webhook
1589+
1590+
:param webhook: The webhook id (required)
1591+
:type webhook: str
1592+
:param _request_timeout: timeout setting for this request. If one
1593+
number provided, it will be total request
1594+
timeout. It can also be a pair (tuple) of
1595+
(connection, read) timeouts.
1596+
:type _request_timeout: int, tuple(int, int), optional
1597+
:param _request_auth: set to override the auth_settings for an a single
1598+
request; this effectively ignores the
1599+
authentication in the spec for a single request.
1600+
:type _request_auth: dict, optional
1601+
:param _content_type: force content-type for the request.
1602+
:type _content_type: str, Optional
1603+
:param _headers: set to override the headers for a single
1604+
request; this effectively ignores the headers
1605+
in the spec for a single request.
1606+
:type _headers: dict, optional
1607+
:param _host_index: set to override the host_index for a single
1608+
request; this effectively ignores the host_index
1609+
in the spec for a single request.
1610+
:type _host_index: int, optional
1611+
:return: Returns the result object.
1612+
""" # noqa: E501
1613+
1614+
_param = self._webhook_requests_list_serialize(
1615+
webhook=webhook,
1616+
_request_auth=_request_auth,
1617+
_content_type=_content_type,
1618+
_headers=_headers,
1619+
_host_index=_host_index,
1620+
)
1621+
1622+
_response_types_map: Dict[str, Optional[str]] = {
1623+
"200": "WebhookWorkerRequestListResponse",
1624+
"400": "APIErrors",
1625+
"401": "APIErrors",
1626+
"405": "APIErrors",
1627+
}
1628+
response_data = await self.api_client.call_api(
1629+
*_param, _request_timeout=_request_timeout
1630+
)
1631+
await response_data.read()
1632+
return self.api_client.response_deserialize(
1633+
response_data=response_data,
1634+
response_types_map=_response_types_map,
1635+
)
1636+
1637+
@validate_call
1638+
async def webhook_requests_list_without_preload_content(
1639+
self,
1640+
webhook: Annotated[
1641+
str,
1642+
Field(
1643+
min_length=36, strict=True, max_length=36, description="The webhook id"
1644+
),
1645+
],
1646+
_request_timeout: Union[
1647+
None,
1648+
Annotated[StrictFloat, Field(gt=0)],
1649+
Tuple[
1650+
Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]
1651+
],
1652+
] = None,
1653+
_request_auth: Optional[Dict[StrictStr, Any]] = None,
1654+
_content_type: Optional[StrictStr] = None,
1655+
_headers: Optional[Dict[StrictStr, Any]] = None,
1656+
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
1657+
) -> RESTResponseType:
1658+
"""List webhook requests
1659+
1660+
Lists all requests for a webhook
1661+
1662+
:param webhook: The webhook id (required)
1663+
:type webhook: str
1664+
:param _request_timeout: timeout setting for this request. If one
1665+
number provided, it will be total request
1666+
timeout. It can also be a pair (tuple) of
1667+
(connection, read) timeouts.
1668+
:type _request_timeout: int, tuple(int, int), optional
1669+
:param _request_auth: set to override the auth_settings for an a single
1670+
request; this effectively ignores the
1671+
authentication in the spec for a single request.
1672+
:type _request_auth: dict, optional
1673+
:param _content_type: force content-type for the request.
1674+
:type _content_type: str, Optional
1675+
:param _headers: set to override the headers for a single
1676+
request; this effectively ignores the headers
1677+
in the spec for a single request.
1678+
:type _headers: dict, optional
1679+
:param _host_index: set to override the host_index for a single
1680+
request; this effectively ignores the host_index
1681+
in the spec for a single request.
1682+
:type _host_index: int, optional
1683+
:return: Returns the result object.
1684+
""" # noqa: E501
1685+
1686+
_param = self._webhook_requests_list_serialize(
1687+
webhook=webhook,
1688+
_request_auth=_request_auth,
1689+
_content_type=_content_type,
1690+
_headers=_headers,
1691+
_host_index=_host_index,
1692+
)
1693+
1694+
_response_types_map: Dict[str, Optional[str]] = {
1695+
"200": "WebhookWorkerRequestListResponse",
1696+
"400": "APIErrors",
1697+
"401": "APIErrors",
1698+
"405": "APIErrors",
1699+
}
1700+
response_data = await self.api_client.call_api(
1701+
*_param, _request_timeout=_request_timeout
1702+
)
1703+
return response_data.response
1704+
1705+
def _webhook_requests_list_serialize(
1706+
self,
1707+
webhook,
1708+
_request_auth,
1709+
_content_type,
1710+
_headers,
1711+
_host_index,
1712+
) -> RequestSerialized:
1713+
1714+
_host = None
1715+
1716+
_collection_formats: Dict[str, str] = {}
1717+
1718+
_path_params: Dict[str, str] = {}
1719+
_query_params: List[Tuple[str, str]] = []
1720+
_header_params: Dict[str, Optional[str]] = _headers or {}
1721+
_form_params: List[Tuple[str, str]] = []
1722+
_files: Dict[str, Union[str, bytes]] = {}
1723+
_body_params: Optional[bytes] = None
1724+
1725+
# process the path parameters
1726+
if webhook is not None:
1727+
_path_params["webhook"] = webhook
1728+
# process the query parameters
1729+
# process the header parameters
1730+
# process the form parameters
1731+
# process the body parameter
1732+
1733+
# set the HTTP header `Accept`
1734+
if "Accept" not in _header_params:
1735+
_header_params["Accept"] = self.api_client.select_header_accept(
1736+
["application/json"]
1737+
)
1738+
1739+
# authentication setting
1740+
_auth_settings: List[str] = ["cookieAuth", "bearerAuth"]
1741+
1742+
return self.api_client.param_serialize(
1743+
method="GET",
1744+
resource_path="/api/v1/webhook-workers/{webhook}/requests",
1745+
path_params=_path_params,
1746+
query_params=_query_params,
1747+
header_params=_header_params,
1748+
body=_body_params,
1749+
post_params=_form_params,
1750+
files=_files,
1751+
auth_settings=_auth_settings,
1752+
collection_formats=_collection_formats,
1753+
_host=_host,
1754+
_request_auth=_request_auth,
1755+
)

0 commit comments

Comments
 (0)