quantumbpm-sdk 1.2.0__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/PKG-INFO +110 -40
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/README.md +109 -38
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/pyproject.toml +1 -2
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/__init__.py +3 -3
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/api/bpmn_api.py +1635 -422
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/api/default_api.py +664 -1232
- quantumbpm_sdk-2.0.0/quantumbpm/auth.py +141 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/bpmn.py +142 -56
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/client.py +33 -9
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/configuration.py +3 -3
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/dmn.py +21 -35
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/exceptions.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/__init__.py +9 -2
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/active_scope.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/batch_evaluate_design_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/batch_evaluation_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/batch_evaluation_response_results_inner.py +1 -1
- quantumbpm_sdk-2.0.0/quantumbpm/models/bpmn_activity_state.py +131 -0
- quantumbpm_sdk-2.0.0/quantumbpm/models/bpmn_element_statistics.py +106 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_external_job_paginated_response.py +4 -4
- quantumbpm_sdk-2.0.0/quantumbpm/models/bpmn_history_page.py +98 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_incident.py +8 -7
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_incident_record.py +10 -15
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_incident_record_paginated_response.py +4 -4
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_instance.py +15 -20
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_instance_children_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_instance_paginated_response.py +4 -4
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_instance_state.py +48 -11
- quantumbpm_sdk-2.0.0/quantumbpm/models/bpmn_instance_status.py +40 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_process_definition.py +5 -5
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_process_summary.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_process_summary_paginated_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_process_version.py +7 -7
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_process_version_paginated_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_resource.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_resource_detail.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_resource_paginated_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_resource_summary.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_resource_summary_paginated_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_user_task_paginated_response.py +4 -4
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_validate_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/bpmn_validation_issue.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/complete_bpmn_external_job_request.py +5 -5
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/complete_bpmn_external_jobs_batch_request.py +2 -2
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/complete_bpmn_external_jobs_batch_request_items_inner.py +4 -4
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/correlation_keys.py +3 -3
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/create_bpmn_resource_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/create_definition_request.py +6 -8
- quantumbpm_sdk-2.0.0/quantumbpm/models/cursor_page.py +92 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/decision_input_field.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/decision_summary.py +3 -3
- quantumbpm_sdk-2.0.0/quantumbpm/models/decision_version.py +97 -0
- quantumbpm_sdk-2.0.0/quantumbpm/models/decision_version_list.py +96 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/definition.py +14 -10
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/element_mapping.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/error.py +4 -4
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/error_mode.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/evaluate_design_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/evaluate_stored_request.py +5 -5
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/evaluation_result.py +5 -3
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/execution.py +33 -17
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/external_job.py +11 -12
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/external_job_batch_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/external_job_batch_response_results_inner.py +2 -2
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/external_job_queue_depth_item.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/external_job_queue_depth_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/feel_warning.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/get_bpmn_instance_variables200_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/get_version200_response.py +3 -7
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/heartbeat_bpmn_external_job_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/hit_rule.py +1 -1
- quantumbpm_sdk-1.2.0/quantumbpm/models/create_project_request.py → quantumbpm_sdk-2.0.0/quantumbpm/models/join_arrivals.py +12 -8
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/migrate_bpmn_instance_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/migration_validation_result.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/modification_instruction.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/modify_bpmn_instance_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/paginated_decisions_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/paginated_definitions_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/paginated_executions_response.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/pagination_metadata.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/poll_bpmn_job_request.py +2 -2
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/project.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/publish_bpmn_message_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/publish_bpmn_signal_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/start_bpmn_instance201_response.py +4 -4
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/start_bpmn_instance_request.py +7 -6
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/start_bpmn_test_instance201_response.py +4 -4
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/start_bpmn_test_instance_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/suspend_bpmn_definition_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/suspend_bpmn_instance_request.py +2 -2
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/suspension_entry.py +4 -3
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/throw_bpmn_external_job_error_request.py +5 -3
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/throw_bpmn_external_job_errors_batch_request.py +2 -2
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/throw_bpmn_external_job_errors_batch_request_items_inner.py +4 -4
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/throw_bpmn_user_task_error_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/trigger_bpmn_ad_hoc_node_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/update_bpmn_instance_variables_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/update_definition_request.py +4 -6
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/update_user_task_assignment_request.py +5 -10
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/user_task.py +14 -12
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/validate_bpmn_resource_request.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/tracing.py +1 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/workers.py +199 -91
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm_sdk.egg-info/PKG-INFO +110 -40
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm_sdk.egg-info/SOURCES.txt +14 -2
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm_sdk.egg-info/requires.txt +0 -1
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/setup.py +1 -2
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/tests/test_business_id_threading.py +44 -31
- quantumbpm_sdk-2.0.0/tests/test_client_credentials.py +145 -0
- quantumbpm_sdk-2.0.0/tests/test_history_args.py +48 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/tests/test_smoke.py +2 -2
- quantumbpm_sdk-2.0.0/tests/test_token_refresh.py +115 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/tests/test_workers_job.py +3 -4
- quantumbpm_sdk-2.0.0/tests/test_workers_options.py +139 -0
- quantumbpm_sdk-2.0.0/tests/test_workers_run.py +230 -0
- quantumbpm_sdk-1.2.0/quantumbpm/auth.py +0 -140
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/LICENSE +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/api/__init__.py +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/api_client.py +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/api_response.py +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/models/feel_value.py +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/py.typed +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/rest.py +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm/variables.py +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm_sdk.egg-info/dependency_links.txt +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/quantumbpm_sdk.egg-info/top_level.txt +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/setup.cfg +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/tests/test_decimal_roundtrip.py +0 -0
- {quantumbpm_sdk-1.2.0 → quantumbpm_sdk-2.0.0}/tests/test_workers_clamp.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quantumbpm-sdk
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: QuantumBPM Python SDK - DMN evaluation, BPMN orchestration, and external job workers.
|
|
5
5
|
Home-page: https://quantumbpm.com
|
|
6
6
|
Author: QuantumBPM
|
|
@@ -14,7 +14,6 @@ Requires-Dist: urllib3<3.0.0,>=2.1.0
|
|
|
14
14
|
Requires-Dist: python-dateutil>=2.8.2
|
|
15
15
|
Requires-Dist: pydantic>=2
|
|
16
16
|
Requires-Dist: typing-extensions>=4.7.1
|
|
17
|
-
Requires-Dist: PyJWT[crypto]>=2.8.0
|
|
18
17
|
Requires-Dist: simplejson>=3.19
|
|
19
18
|
Requires-Dist: requests>=2.31.0
|
|
20
19
|
Dynamic: author
|
|
@@ -39,7 +38,7 @@ Python 3.10+. Async-first; built on `asyncio`.
|
|
|
39
38
|
| Module | Purpose |
|
|
40
39
|
| ------------------------- | ----------------------------------------------------------------------------- |
|
|
41
40
|
| `quantumbpm.QuantumBPM` | Top-level client exposing `.dmn`, `.bpmn`, plus `new_worker(...)` |
|
|
42
|
-
| `quantumbpm.auth` | `TokenProvider`, `
|
|
41
|
+
| `quantumbpm.auth` | `TokenProvider`, `ClientCredentialsTokenProvider`, `StaticTokenProvider` |
|
|
43
42
|
| `quantumbpm.dmn` | DMN evaluation: stored definitions, ad-hoc XML, batch |
|
|
44
43
|
| `quantumbpm.bpmn` | BPMN resources, instances, messaging, user tasks, processes |
|
|
45
44
|
| `quantumbpm.workers` | External job worker runtime - long-poll, lock heartbeat, dispatch |
|
|
@@ -50,17 +49,18 @@ Python 3.10+. Async-first; built on `asyncio`.
|
|
|
50
49
|
|
|
51
50
|
```python
|
|
52
51
|
import asyncio
|
|
53
|
-
|
|
52
|
+
import os
|
|
53
|
+
from quantumbpm import ClientCredentialsTokenProvider, QuantumBPM, Vars
|
|
54
54
|
|
|
55
55
|
async def main():
|
|
56
|
-
provider =
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
56
|
+
provider = ClientCredentialsTokenProvider(
|
|
57
|
+
token_url="https://idp.example.com/realms/acme/protocol/openid-connect/token",
|
|
58
|
+
client_id="billing-svc",
|
|
59
|
+
client_secret=os.environ["QUANTUMBPM_CLIENT_SECRET"],
|
|
60
60
|
)
|
|
61
61
|
|
|
62
62
|
async with QuantumBPM(
|
|
63
|
-
base_url="https://
|
|
63
|
+
base_url="https://quantumbpm.example.com",
|
|
64
64
|
project_id="00000000-0000-0000-0000-000000000000",
|
|
65
65
|
token_provider=provider,
|
|
66
66
|
) as client:
|
|
@@ -73,30 +73,39 @@ async def main():
|
|
|
73
73
|
asyncio.run(main())
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
The async context manager (`async with`)
|
|
76
|
+
The async context manager (`async with`) fetches a bearer token on entry, so an authentication problem shows up right away. Every API call also asks the token provider for a token first, so calling methods without the context manager works too, and a long-running worker keeps sending a valid token.
|
|
77
77
|
|
|
78
78
|
## Authentication
|
|
79
79
|
|
|
80
|
-
The `TokenProvider`
|
|
80
|
+
The SDK awaits `TokenProvider.get_token()` before every API call and sends the result as the bearer token. Two implementations ship out of the box.
|
|
81
81
|
|
|
82
|
-
###
|
|
82
|
+
### OAuth 2.0 client credentials
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
from quantumbpm import ZitadelTokenProvider
|
|
84
|
+
`ClientCredentialsTokenProvider` fetches access tokens from your OIDC identity provider (Keycloak, Microsoft Entra ID, Okta, Auth0 and others) with the client credentials grant. Register a confidential client for your service at the identity provider and pass its token endpoint and credentials:
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
```python
|
|
87
|
+
import os
|
|
88
|
+
from quantumbpm import ClientCredentialsTokenProvider
|
|
89
|
+
|
|
90
|
+
provider = ClientCredentialsTokenProvider(
|
|
91
|
+
token_url="https://idp.example.com/realms/acme/protocol/openid-connect/token",
|
|
92
|
+
client_id="billing-svc",
|
|
93
|
+
client_secret=os.environ["QUANTUMBPM_CLIENT_SECRET"],
|
|
94
|
+
scopes=["openid"], # optional
|
|
95
|
+
audience="quantumbpm", # optional, some providers such as Auth0 require it
|
|
96
|
+
ssl_ca_cert="/path/to/ca.crt", # optional, for an identity provider behind a private CA
|
|
92
97
|
)
|
|
93
98
|
```
|
|
94
99
|
|
|
95
|
-
The provider
|
|
100
|
+
The exact token endpoint depends on the identity provider. The provider's OIDC discovery document (`/.well-known/openid-configuration`) lists it as `token_endpoint`.
|
|
101
|
+
|
|
102
|
+
`scopes` are sent space-joined as the `scope` parameter and `audience` as the `audience` parameter. Each is left out of the request when empty. The client must be set up at the identity provider so its tokens carry the audience and roles your QuantumBPM deployment expects.
|
|
103
|
+
|
|
104
|
+
The provider caches the token in memory and fetches a new one once less than 60 seconds of its lifetime remain, so the lookup before each call is cheap. Concurrent callers wait for one shared request. A non-2xx response from the token endpoint raises `quantumbpm.exceptions.ApiException` with the HTTP status and response body.
|
|
96
105
|
|
|
97
106
|
### Static bearer token
|
|
98
107
|
|
|
99
|
-
For
|
|
108
|
+
For a token acquired out of band, for example by another library or in tests:
|
|
100
109
|
|
|
101
110
|
```python
|
|
102
111
|
from quantumbpm import StaticTokenProvider
|
|
@@ -118,6 +127,8 @@ class MyProvider:
|
|
|
118
127
|
provider: TokenProvider = MyProvider()
|
|
119
128
|
```
|
|
120
129
|
|
|
130
|
+
`get_token` runs before every API call, so cache the token when fetching one is expensive.
|
|
131
|
+
|
|
121
132
|
## DMN evaluation
|
|
122
133
|
|
|
123
134
|
The `client.dmn` sub-client offers four async methods.
|
|
@@ -144,14 +155,6 @@ result = await client.dmn.evaluate(
|
|
|
144
155
|
)
|
|
145
156
|
```
|
|
146
157
|
|
|
147
|
-
### Evaluate by platform UUID
|
|
148
|
-
|
|
149
|
-
When you already hold a database-version pointer:
|
|
150
|
-
|
|
151
|
-
```python
|
|
152
|
-
result = await client.dmn.evaluate_by_id(definition_uuid, vars)
|
|
153
|
-
```
|
|
154
|
-
|
|
155
158
|
### Ad-hoc XML evaluation
|
|
156
159
|
|
|
157
160
|
For "evaluate while editing" flows that don't store the XML:
|
|
@@ -186,12 +189,13 @@ batch = await client.dmn.evaluate_design_batch(dmn_xml, rows)
|
|
|
186
189
|
draft = await client.bpmn.create_resource("loan-process", bpmn_xml)
|
|
187
190
|
await client.bpmn.deploy_resource(draft.id)
|
|
188
191
|
|
|
189
|
-
# Re-fetch to get the
|
|
192
|
+
# Re-fetch to get the process versions the deploy created.
|
|
190
193
|
deployed = await client.bpmn.get_resource(draft.id)
|
|
191
194
|
process_def = deployed.processes[0]
|
|
192
195
|
|
|
193
|
-
|
|
194
|
-
|
|
196
|
+
# Starts the latest version. Pass version=N to pick one.
|
|
197
|
+
instance_id = await client.bpmn.start_instance(
|
|
198
|
+
process_def.process_id,
|
|
195
199
|
Vars().set("applicantID", "u-123").set("requestedAmt", 25000),
|
|
196
200
|
)
|
|
197
201
|
```
|
|
@@ -199,12 +203,19 @@ workflow_id = await client.bpmn.start_instance(
|
|
|
199
203
|
### Inspect runtime state
|
|
200
204
|
|
|
201
205
|
```python
|
|
202
|
-
state = await client.bpmn.get_instance(
|
|
206
|
+
state = await client.bpmn.get_instance(instance_id)
|
|
203
207
|
print(state.status, state.active_scopes)
|
|
204
208
|
|
|
205
|
-
vars = await client.bpmn.get_instance_variables(
|
|
209
|
+
vars = await client.bpmn.get_instance_variables(instance_id)
|
|
206
210
|
|
|
207
|
-
children = await client.bpmn.get_instance_children(
|
|
211
|
+
children = await client.bpmn.get_instance_children(instance_id)
|
|
212
|
+
|
|
213
|
+
# History pages run oldest first. Without options a page holds the newest
|
|
214
|
+
# entries, and an entry read by its seq carries its inputs and outputs.
|
|
215
|
+
page = await client.bpmn.get_instance_history(instance_id, from_seq=1, limit=100)
|
|
216
|
+
entry = await client.bpmn.get_instance_history_entry(instance_id, page.items[0].seq)
|
|
217
|
+
|
|
218
|
+
version = await client.bpmn.get_process_version("loan-process", 2)
|
|
208
219
|
```
|
|
209
220
|
|
|
210
221
|
### Send messages and signals
|
|
@@ -228,6 +239,19 @@ page = await client.bpmn.list_user_tasks(
|
|
|
228
239
|
status="CREATED",
|
|
229
240
|
)
|
|
230
241
|
|
|
242
|
+
# Lists of instances and user tasks page by cursor: pass the page's
|
|
243
|
+
# next_cursor back for the next one. It is None on the last page.
|
|
244
|
+
if page.pagination.next_cursor:
|
|
245
|
+
page = await client.bpmn.list_user_tasks(
|
|
246
|
+
assignee="alice@example.com",
|
|
247
|
+
status="CREATED",
|
|
248
|
+
cursor=page.pagination.next_cursor,
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
# The caller's tasks soonest due first, and the project's overdue ones.
|
|
252
|
+
mine = await client.bpmn.list_user_tasks_for_caller(sort="dueDate")
|
|
253
|
+
overdue = await client.bpmn.list_user_tasks(status="CREATED", due_before=datetime.now(timezone.utc))
|
|
254
|
+
|
|
231
255
|
await client.bpmn.complete_user_task(execution_key, Vars().set("approved", True))
|
|
232
256
|
|
|
233
257
|
# Or fail with a BPMN error code (matches boundary error events):
|
|
@@ -262,7 +286,7 @@ async def main():
|
|
|
262
286
|
asyncio.run(main())
|
|
263
287
|
```
|
|
264
288
|
|
|
265
|
-
`run(stop)` resolves
|
|
289
|
+
`run(stop)` resolves once the `asyncio.Event` is set and running handlers have finished, or the shutdown timeout has passed. See [Heartbeats, lost locks, and shutdown](#heartbeats-lost-locks-and-shutdown).
|
|
266
290
|
|
|
267
291
|
### Concurrency, polling, and locks
|
|
268
292
|
|
|
@@ -270,14 +294,57 @@ asyncio.run(main())
|
|
|
270
294
|
@worker.handler(
|
|
271
295
|
"send-email",
|
|
272
296
|
max_jobs=10, # up to 10 in flight per task type
|
|
273
|
-
poll_timeout="
|
|
297
|
+
poll_timeout="5s", # long-poll wait per request, at most 5s
|
|
274
298
|
lock_duration="2m", # exclusive lock per job
|
|
275
299
|
)
|
|
276
300
|
async def handle(job: Job) -> Vars:
|
|
277
301
|
...
|
|
278
302
|
```
|
|
279
303
|
|
|
280
|
-
Concurrency is per task type. Different task types run independently.
|
|
304
|
+
Concurrency is per task type. Different task types run independently.
|
|
305
|
+
|
|
306
|
+
`poll_timeout` and `lock_duration` take Go duration strings such as `30s`, `1m30s`, `12.5s` or `500ms`. `handler` and `handle` raise `ValueError` for a value that does not parse. One poll request waits at most 5 seconds on the server, and a larger `poll_timeout` is capped to that. When a poll returns no job, the worker polls again right away.
|
|
307
|
+
|
|
308
|
+
The server clamps every lock to between 10 seconds and 5 minutes by default (`ENGINE_WORKER_LOCK_MIN` and `ENGINE_WORKER_LOCK_MAX`). Each polled job carries `job.raw.lock_expires_at`, the expiry of the lock the server granted. While the handler runs, the runtime heartbeats at half of the granted lock, or at half of `lock_duration` when that is shorter. A `lock_duration` of `11m` gets a 5 minute lock and a heartbeat every 2.5 minutes.
|
|
309
|
+
|
|
310
|
+
### Heartbeats, lost locks, and shutdown
|
|
311
|
+
|
|
312
|
+
A polled job is locked to this worker. Each heartbeat extends the lock by `lock_duration`, clamped the same way, and the server caps one attempt at 30 minutes by default (`ENGINE_JOB_MAX_HOLD`). When the lock runs out, the server charges the job a retry and offers it again, or raises an incident when no retries are left. So abandoning a running job always costs a retry.
|
|
313
|
+
|
|
314
|
+
When a heartbeat answers that this worker no longer holds the job (HTTP 409 or 404), the runtime cancels the handler with `asyncio.CancelledError` and reports nothing. A complete or error report rejected with 409 is discarded by the server and logged as a warning. Let `CancelledError` propagate out of handlers.
|
|
315
|
+
|
|
316
|
+
Setting the `stop` event shuts the worker down gracefully:
|
|
317
|
+
|
|
318
|
+
- No new poll starts. A poll already in flight cannot be cancelled. It returns within 5 seconds, and jobs it returns before the shutdown timeout still run.
|
|
319
|
+
- Running handlers keep heartbeating, and their results are reported.
|
|
320
|
+
- Handlers still running `shutdown_timeout` seconds (default `20.0`) after `stop` is set are cancelled and not reported. Their locks run out on the server. Then `run` returns.
|
|
321
|
+
|
|
322
|
+
Wire `stop` to SIGTERM so a stop signal drains the worker:
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
import asyncio
|
|
326
|
+
import signal
|
|
327
|
+
from quantumbpm import QuantumBPM, Vars
|
|
328
|
+
from quantumbpm.workers import Job
|
|
329
|
+
|
|
330
|
+
async def main():
|
|
331
|
+
async with QuantumBPM(...) as client:
|
|
332
|
+
worker = client.new_worker(client_id="billing-svc", shutdown_timeout=20.0)
|
|
333
|
+
|
|
334
|
+
@worker.handler("send-email")
|
|
335
|
+
async def handle(job: Job) -> Vars:
|
|
336
|
+
...
|
|
337
|
+
|
|
338
|
+
stop = asyncio.Event()
|
|
339
|
+
loop = asyncio.get_running_loop()
|
|
340
|
+
loop.add_signal_handler(signal.SIGTERM, stop.set)
|
|
341
|
+
loop.add_signal_handler(signal.SIGINT, stop.set)
|
|
342
|
+
await worker.run(stop)
|
|
343
|
+
|
|
344
|
+
asyncio.run(main())
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
On Kubernetes, set `terminationGracePeriodSeconds` above the shutdown timeout, or the pod is killed mid-drain. A poll in flight at stop can also hold process exit for up to 5 seconds, so leave room for that too.
|
|
281
348
|
|
|
282
349
|
### Throwing typed BPMN errors
|
|
283
350
|
|
|
@@ -293,7 +360,7 @@ async def handle(job: Job) -> Vars:
|
|
|
293
360
|
raise BpmnError("INSUFFICIENT_FUNDS", Vars().set("availableBalance", 12.0))
|
|
294
361
|
```
|
|
295
362
|
|
|
296
|
-
Any other exception is reported as `WORKER_ERROR`, which the server treats as a retryable failure that decrements the job's retry budget.
|
|
363
|
+
Any other exception is reported as `WORKER_ERROR`, which the server treats as a retryable failure that decrements the job's retry budget. The exception message goes into the `error` variable, cut to `max_error_message_bytes` bytes of UTF-8 (a `new_worker` option, default 2048).
|
|
297
364
|
|
|
298
365
|
### Typed handlers (Pydantic)
|
|
299
366
|
|
|
@@ -348,10 +415,13 @@ The `client.raw` property exposes the underlying generated `ApiClient` for endpo
|
|
|
348
415
|
```python
|
|
349
416
|
from quantumbpm.api.bpmn_api import BpmnApi
|
|
350
417
|
|
|
418
|
+
await client.authenticate()
|
|
351
419
|
api = BpmnApi(client.raw)
|
|
352
|
-
result = api.migrate_bpmn_instance(client.project_id,
|
|
420
|
+
result = api.migrate_bpmn_instance(client.project_id, instance_id, body)
|
|
353
421
|
```
|
|
354
422
|
|
|
423
|
+
Calls through `client.raw` send the token of the last SDK call. `await client.authenticate()` puts a current token on it first.
|
|
424
|
+
|
|
355
425
|
## License
|
|
356
426
|
|
|
357
427
|
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -15,7 +15,7 @@ Python 3.10+. Async-first; built on `asyncio`.
|
|
|
15
15
|
| Module | Purpose |
|
|
16
16
|
| ------------------------- | ----------------------------------------------------------------------------- |
|
|
17
17
|
| `quantumbpm.QuantumBPM` | Top-level client exposing `.dmn`, `.bpmn`, plus `new_worker(...)` |
|
|
18
|
-
| `quantumbpm.auth` | `TokenProvider`, `
|
|
18
|
+
| `quantumbpm.auth` | `TokenProvider`, `ClientCredentialsTokenProvider`, `StaticTokenProvider` |
|
|
19
19
|
| `quantumbpm.dmn` | DMN evaluation: stored definitions, ad-hoc XML, batch |
|
|
20
20
|
| `quantumbpm.bpmn` | BPMN resources, instances, messaging, user tasks, processes |
|
|
21
21
|
| `quantumbpm.workers` | External job worker runtime - long-poll, lock heartbeat, dispatch |
|
|
@@ -26,17 +26,18 @@ Python 3.10+. Async-first; built on `asyncio`.
|
|
|
26
26
|
|
|
27
27
|
```python
|
|
28
28
|
import asyncio
|
|
29
|
-
|
|
29
|
+
import os
|
|
30
|
+
from quantumbpm import ClientCredentialsTokenProvider, QuantumBPM, Vars
|
|
30
31
|
|
|
31
32
|
async def main():
|
|
32
|
-
provider =
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
33
|
+
provider = ClientCredentialsTokenProvider(
|
|
34
|
+
token_url="https://idp.example.com/realms/acme/protocol/openid-connect/token",
|
|
35
|
+
client_id="billing-svc",
|
|
36
|
+
client_secret=os.environ["QUANTUMBPM_CLIENT_SECRET"],
|
|
36
37
|
)
|
|
37
38
|
|
|
38
39
|
async with QuantumBPM(
|
|
39
|
-
base_url="https://
|
|
40
|
+
base_url="https://quantumbpm.example.com",
|
|
40
41
|
project_id="00000000-0000-0000-0000-000000000000",
|
|
41
42
|
token_provider=provider,
|
|
42
43
|
) as client:
|
|
@@ -49,30 +50,39 @@ async def main():
|
|
|
49
50
|
asyncio.run(main())
|
|
50
51
|
```
|
|
51
52
|
|
|
52
|
-
The async context manager (`async with`)
|
|
53
|
+
The async context manager (`async with`) fetches a bearer token on entry, so an authentication problem shows up right away. Every API call also asks the token provider for a token first, so calling methods without the context manager works too, and a long-running worker keeps sending a valid token.
|
|
53
54
|
|
|
54
55
|
## Authentication
|
|
55
56
|
|
|
56
|
-
The `TokenProvider`
|
|
57
|
+
The SDK awaits `TokenProvider.get_token()` before every API call and sends the result as the bearer token. Two implementations ship out of the box.
|
|
57
58
|
|
|
58
|
-
###
|
|
59
|
+
### OAuth 2.0 client credentials
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
from quantumbpm import ZitadelTokenProvider
|
|
61
|
+
`ClientCredentialsTokenProvider` fetches access tokens from your OIDC identity provider (Keycloak, Microsoft Entra ID, Okta, Auth0 and others) with the client credentials grant. Register a confidential client for your service at the identity provider and pass its token endpoint and credentials:
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
```python
|
|
64
|
+
import os
|
|
65
|
+
from quantumbpm import ClientCredentialsTokenProvider
|
|
66
|
+
|
|
67
|
+
provider = ClientCredentialsTokenProvider(
|
|
68
|
+
token_url="https://idp.example.com/realms/acme/protocol/openid-connect/token",
|
|
69
|
+
client_id="billing-svc",
|
|
70
|
+
client_secret=os.environ["QUANTUMBPM_CLIENT_SECRET"],
|
|
71
|
+
scopes=["openid"], # optional
|
|
72
|
+
audience="quantumbpm", # optional, some providers such as Auth0 require it
|
|
73
|
+
ssl_ca_cert="/path/to/ca.crt", # optional, for an identity provider behind a private CA
|
|
68
74
|
)
|
|
69
75
|
```
|
|
70
76
|
|
|
71
|
-
The provider
|
|
77
|
+
The exact token endpoint depends on the identity provider. The provider's OIDC discovery document (`/.well-known/openid-configuration`) lists it as `token_endpoint`.
|
|
78
|
+
|
|
79
|
+
`scopes` are sent space-joined as the `scope` parameter and `audience` as the `audience` parameter. Each is left out of the request when empty. The client must be set up at the identity provider so its tokens carry the audience and roles your QuantumBPM deployment expects.
|
|
80
|
+
|
|
81
|
+
The provider caches the token in memory and fetches a new one once less than 60 seconds of its lifetime remain, so the lookup before each call is cheap. Concurrent callers wait for one shared request. A non-2xx response from the token endpoint raises `quantumbpm.exceptions.ApiException` with the HTTP status and response body.
|
|
72
82
|
|
|
73
83
|
### Static bearer token
|
|
74
84
|
|
|
75
|
-
For
|
|
85
|
+
For a token acquired out of band, for example by another library or in tests:
|
|
76
86
|
|
|
77
87
|
```python
|
|
78
88
|
from quantumbpm import StaticTokenProvider
|
|
@@ -94,6 +104,8 @@ class MyProvider:
|
|
|
94
104
|
provider: TokenProvider = MyProvider()
|
|
95
105
|
```
|
|
96
106
|
|
|
107
|
+
`get_token` runs before every API call, so cache the token when fetching one is expensive.
|
|
108
|
+
|
|
97
109
|
## DMN evaluation
|
|
98
110
|
|
|
99
111
|
The `client.dmn` sub-client offers four async methods.
|
|
@@ -120,14 +132,6 @@ result = await client.dmn.evaluate(
|
|
|
120
132
|
)
|
|
121
133
|
```
|
|
122
134
|
|
|
123
|
-
### Evaluate by platform UUID
|
|
124
|
-
|
|
125
|
-
When you already hold a database-version pointer:
|
|
126
|
-
|
|
127
|
-
```python
|
|
128
|
-
result = await client.dmn.evaluate_by_id(definition_uuid, vars)
|
|
129
|
-
```
|
|
130
|
-
|
|
131
135
|
### Ad-hoc XML evaluation
|
|
132
136
|
|
|
133
137
|
For "evaluate while editing" flows that don't store the XML:
|
|
@@ -162,12 +166,13 @@ batch = await client.dmn.evaluate_design_batch(dmn_xml, rows)
|
|
|
162
166
|
draft = await client.bpmn.create_resource("loan-process", bpmn_xml)
|
|
163
167
|
await client.bpmn.deploy_resource(draft.id)
|
|
164
168
|
|
|
165
|
-
# Re-fetch to get the
|
|
169
|
+
# Re-fetch to get the process versions the deploy created.
|
|
166
170
|
deployed = await client.bpmn.get_resource(draft.id)
|
|
167
171
|
process_def = deployed.processes[0]
|
|
168
172
|
|
|
169
|
-
|
|
170
|
-
|
|
173
|
+
# Starts the latest version. Pass version=N to pick one.
|
|
174
|
+
instance_id = await client.bpmn.start_instance(
|
|
175
|
+
process_def.process_id,
|
|
171
176
|
Vars().set("applicantID", "u-123").set("requestedAmt", 25000),
|
|
172
177
|
)
|
|
173
178
|
```
|
|
@@ -175,12 +180,19 @@ workflow_id = await client.bpmn.start_instance(
|
|
|
175
180
|
### Inspect runtime state
|
|
176
181
|
|
|
177
182
|
```python
|
|
178
|
-
state = await client.bpmn.get_instance(
|
|
183
|
+
state = await client.bpmn.get_instance(instance_id)
|
|
179
184
|
print(state.status, state.active_scopes)
|
|
180
185
|
|
|
181
|
-
vars = await client.bpmn.get_instance_variables(
|
|
186
|
+
vars = await client.bpmn.get_instance_variables(instance_id)
|
|
182
187
|
|
|
183
|
-
children = await client.bpmn.get_instance_children(
|
|
188
|
+
children = await client.bpmn.get_instance_children(instance_id)
|
|
189
|
+
|
|
190
|
+
# History pages run oldest first. Without options a page holds the newest
|
|
191
|
+
# entries, and an entry read by its seq carries its inputs and outputs.
|
|
192
|
+
page = await client.bpmn.get_instance_history(instance_id, from_seq=1, limit=100)
|
|
193
|
+
entry = await client.bpmn.get_instance_history_entry(instance_id, page.items[0].seq)
|
|
194
|
+
|
|
195
|
+
version = await client.bpmn.get_process_version("loan-process", 2)
|
|
184
196
|
```
|
|
185
197
|
|
|
186
198
|
### Send messages and signals
|
|
@@ -204,6 +216,19 @@ page = await client.bpmn.list_user_tasks(
|
|
|
204
216
|
status="CREATED",
|
|
205
217
|
)
|
|
206
218
|
|
|
219
|
+
# Lists of instances and user tasks page by cursor: pass the page's
|
|
220
|
+
# next_cursor back for the next one. It is None on the last page.
|
|
221
|
+
if page.pagination.next_cursor:
|
|
222
|
+
page = await client.bpmn.list_user_tasks(
|
|
223
|
+
assignee="alice@example.com",
|
|
224
|
+
status="CREATED",
|
|
225
|
+
cursor=page.pagination.next_cursor,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
# The caller's tasks soonest due first, and the project's overdue ones.
|
|
229
|
+
mine = await client.bpmn.list_user_tasks_for_caller(sort="dueDate")
|
|
230
|
+
overdue = await client.bpmn.list_user_tasks(status="CREATED", due_before=datetime.now(timezone.utc))
|
|
231
|
+
|
|
207
232
|
await client.bpmn.complete_user_task(execution_key, Vars().set("approved", True))
|
|
208
233
|
|
|
209
234
|
# Or fail with a BPMN error code (matches boundary error events):
|
|
@@ -238,7 +263,7 @@ async def main():
|
|
|
238
263
|
asyncio.run(main())
|
|
239
264
|
```
|
|
240
265
|
|
|
241
|
-
`run(stop)` resolves
|
|
266
|
+
`run(stop)` resolves once the `asyncio.Event` is set and running handlers have finished, or the shutdown timeout has passed. See [Heartbeats, lost locks, and shutdown](#heartbeats-lost-locks-and-shutdown).
|
|
242
267
|
|
|
243
268
|
### Concurrency, polling, and locks
|
|
244
269
|
|
|
@@ -246,14 +271,57 @@ asyncio.run(main())
|
|
|
246
271
|
@worker.handler(
|
|
247
272
|
"send-email",
|
|
248
273
|
max_jobs=10, # up to 10 in flight per task type
|
|
249
|
-
poll_timeout="
|
|
274
|
+
poll_timeout="5s", # long-poll wait per request, at most 5s
|
|
250
275
|
lock_duration="2m", # exclusive lock per job
|
|
251
276
|
)
|
|
252
277
|
async def handle(job: Job) -> Vars:
|
|
253
278
|
...
|
|
254
279
|
```
|
|
255
280
|
|
|
256
|
-
Concurrency is per task type. Different task types run independently.
|
|
281
|
+
Concurrency is per task type. Different task types run independently.
|
|
282
|
+
|
|
283
|
+
`poll_timeout` and `lock_duration` take Go duration strings such as `30s`, `1m30s`, `12.5s` or `500ms`. `handler` and `handle` raise `ValueError` for a value that does not parse. One poll request waits at most 5 seconds on the server, and a larger `poll_timeout` is capped to that. When a poll returns no job, the worker polls again right away.
|
|
284
|
+
|
|
285
|
+
The server clamps every lock to between 10 seconds and 5 minutes by default (`ENGINE_WORKER_LOCK_MIN` and `ENGINE_WORKER_LOCK_MAX`). Each polled job carries `job.raw.lock_expires_at`, the expiry of the lock the server granted. While the handler runs, the runtime heartbeats at half of the granted lock, or at half of `lock_duration` when that is shorter. A `lock_duration` of `11m` gets a 5 minute lock and a heartbeat every 2.5 minutes.
|
|
286
|
+
|
|
287
|
+
### Heartbeats, lost locks, and shutdown
|
|
288
|
+
|
|
289
|
+
A polled job is locked to this worker. Each heartbeat extends the lock by `lock_duration`, clamped the same way, and the server caps one attempt at 30 minutes by default (`ENGINE_JOB_MAX_HOLD`). When the lock runs out, the server charges the job a retry and offers it again, or raises an incident when no retries are left. So abandoning a running job always costs a retry.
|
|
290
|
+
|
|
291
|
+
When a heartbeat answers that this worker no longer holds the job (HTTP 409 or 404), the runtime cancels the handler with `asyncio.CancelledError` and reports nothing. A complete or error report rejected with 409 is discarded by the server and logged as a warning. Let `CancelledError` propagate out of handlers.
|
|
292
|
+
|
|
293
|
+
Setting the `stop` event shuts the worker down gracefully:
|
|
294
|
+
|
|
295
|
+
- No new poll starts. A poll already in flight cannot be cancelled. It returns within 5 seconds, and jobs it returns before the shutdown timeout still run.
|
|
296
|
+
- Running handlers keep heartbeating, and their results are reported.
|
|
297
|
+
- Handlers still running `shutdown_timeout` seconds (default `20.0`) after `stop` is set are cancelled and not reported. Their locks run out on the server. Then `run` returns.
|
|
298
|
+
|
|
299
|
+
Wire `stop` to SIGTERM so a stop signal drains the worker:
|
|
300
|
+
|
|
301
|
+
```python
|
|
302
|
+
import asyncio
|
|
303
|
+
import signal
|
|
304
|
+
from quantumbpm import QuantumBPM, Vars
|
|
305
|
+
from quantumbpm.workers import Job
|
|
306
|
+
|
|
307
|
+
async def main():
|
|
308
|
+
async with QuantumBPM(...) as client:
|
|
309
|
+
worker = client.new_worker(client_id="billing-svc", shutdown_timeout=20.0)
|
|
310
|
+
|
|
311
|
+
@worker.handler("send-email")
|
|
312
|
+
async def handle(job: Job) -> Vars:
|
|
313
|
+
...
|
|
314
|
+
|
|
315
|
+
stop = asyncio.Event()
|
|
316
|
+
loop = asyncio.get_running_loop()
|
|
317
|
+
loop.add_signal_handler(signal.SIGTERM, stop.set)
|
|
318
|
+
loop.add_signal_handler(signal.SIGINT, stop.set)
|
|
319
|
+
await worker.run(stop)
|
|
320
|
+
|
|
321
|
+
asyncio.run(main())
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
On Kubernetes, set `terminationGracePeriodSeconds` above the shutdown timeout, or the pod is killed mid-drain. A poll in flight at stop can also hold process exit for up to 5 seconds, so leave room for that too.
|
|
257
325
|
|
|
258
326
|
### Throwing typed BPMN errors
|
|
259
327
|
|
|
@@ -269,7 +337,7 @@ async def handle(job: Job) -> Vars:
|
|
|
269
337
|
raise BpmnError("INSUFFICIENT_FUNDS", Vars().set("availableBalance", 12.0))
|
|
270
338
|
```
|
|
271
339
|
|
|
272
|
-
Any other exception is reported as `WORKER_ERROR`, which the server treats as a retryable failure that decrements the job's retry budget.
|
|
340
|
+
Any other exception is reported as `WORKER_ERROR`, which the server treats as a retryable failure that decrements the job's retry budget. The exception message goes into the `error` variable, cut to `max_error_message_bytes` bytes of UTF-8 (a `new_worker` option, default 2048).
|
|
273
341
|
|
|
274
342
|
### Typed handlers (Pydantic)
|
|
275
343
|
|
|
@@ -324,10 +392,13 @@ The `client.raw` property exposes the underlying generated `ApiClient` for endpo
|
|
|
324
392
|
```python
|
|
325
393
|
from quantumbpm.api.bpmn_api import BpmnApi
|
|
326
394
|
|
|
395
|
+
await client.authenticate()
|
|
327
396
|
api = BpmnApi(client.raw)
|
|
328
|
-
result = api.migrate_bpmn_instance(client.project_id,
|
|
397
|
+
result = api.migrate_bpmn_instance(client.project_id, instance_id, body)
|
|
329
398
|
```
|
|
330
399
|
|
|
400
|
+
Calls through `client.raw` send the token of the last SDK call. `await client.authenticate()` puts a current token on it first.
|
|
401
|
+
|
|
331
402
|
## License
|
|
332
403
|
|
|
333
404
|
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "quantumbpm-sdk"
|
|
3
|
-
version = "
|
|
3
|
+
version = "2.0.0"
|
|
4
4
|
description = "QuantumBPM Python SDK - DMN evaluation, BPMN orchestration, and external job workers."
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "QuantumBPM",email = "support@quantumbpm.com"},
|
|
@@ -14,7 +14,6 @@ dependencies = [
|
|
|
14
14
|
"python-dateutil (>=2.8.2)",
|
|
15
15
|
"pydantic (>=2)",
|
|
16
16
|
"typing-extensions (>=4.7.1)",
|
|
17
|
-
"PyJWT[crypto] (>=2.8.0)",
|
|
18
17
|
"simplejson (>=3.19)",
|
|
19
18
|
"requests (>=2.31.0)",
|
|
20
19
|
]
|
|
@@ -9,9 +9,9 @@ endpoints not yet wrapped.
|
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
11
|
from quantumbpm.auth import (
|
|
12
|
+
ClientCredentialsTokenProvider,
|
|
12
13
|
StaticTokenProvider,
|
|
13
14
|
TokenProvider,
|
|
14
|
-
ZitadelTokenProvider,
|
|
15
15
|
)
|
|
16
16
|
from quantumbpm.bpmn import BpmnClient
|
|
17
17
|
from quantumbpm.client import QuantumBPM
|
|
@@ -19,11 +19,12 @@ from quantumbpm.dmn import DmnClient, DmnResult
|
|
|
19
19
|
from quantumbpm.variables import Vars
|
|
20
20
|
from quantumbpm.workers import BpmnError, Handler, Job, Worker
|
|
21
21
|
|
|
22
|
-
__version__ = "
|
|
22
|
+
__version__ = "2.0.0"
|
|
23
23
|
|
|
24
24
|
__all__ = [
|
|
25
25
|
"BpmnClient",
|
|
26
26
|
"BpmnError",
|
|
27
|
+
"ClientCredentialsTokenProvider",
|
|
27
28
|
"DmnClient",
|
|
28
29
|
"DmnResult",
|
|
29
30
|
"Handler",
|
|
@@ -33,5 +34,4 @@ __all__ = [
|
|
|
33
34
|
"TokenProvider",
|
|
34
35
|
"Vars",
|
|
35
36
|
"Worker",
|
|
36
|
-
"ZitadelTokenProvider",
|
|
37
37
|
]
|