Temporal¶
The temporal adapter provides integration with Temporal, a durable workflow orchestration platform, including workflow
and activity definitions, worker management, and runtime configuration.
Ports¶
Abstract port interface defining the Temporal adapter contract.
Port interfaces for Temporal workflow orchestration.
This module defines the abstract interfaces for Temporal workflow and activity operations, providing a standardized contract for workflow orchestration within the ArchiPy architecture.
archipy.adapters.temporal.ports.TemporalPort ¶
Interface for Temporal workflow operations providing a standardized access pattern.
This interface defines the contract for Temporal adapters, ensuring consistent implementation of workflow operations across different adapters. It covers workflow lifecycle management, execution control, and query operations.
Implementing classes should provide concrete implementations for all methods, typically by wrapping a Temporal client library.
Source code in archipy/adapters/temporal/ports.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
archipy.adapters.temporal.ports.TemporalPort.start_workflow
abstractmethod
async
¶
start_workflow(
workflow: str | Callable,
arg: Any = None,
workflow_id: str | None = None,
task_queue: str | None = None,
execution_timeout: int | None = None,
run_timeout: int | None = None,
task_timeout: int | None = None,
memo: dict[str, Any] | None = None,
search_attributes: dict[str, Any] | None = None,
) -> Any
Start a workflow execution asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
str | Callable
|
The workflow function or workflow type name. |
required |
arg
|
Any
|
Input argument for the workflow. Defaults to None. |
None
|
workflow_id
|
str
|
Unique identifier for the workflow execution. If None, a UUID will be generated. Defaults to None. |
None
|
task_queue
|
str
|
Task queue name for workflow execution. If None, uses the default task queue. Defaults to None. |
None
|
execution_timeout
|
int
|
Maximum workflow execution time in seconds. Overrides config default. Defaults to None. |
None
|
run_timeout
|
int
|
Maximum single workflow run time in seconds. Overrides config default. Defaults to None. |
None
|
task_timeout
|
int
|
Maximum workflow task processing time in seconds. Overrides config default. Defaults to None. |
None
|
memo
|
dict[str, Any]
|
Non-indexed metadata for the workflow. Defaults to None. |
None
|
search_attributes
|
dict[str, Any]
|
Indexed metadata for workflow search. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
WorkflowHandle[T, Any]: Handle to the started workflow execution. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.execute_workflow
abstractmethod
async
¶
execute_workflow(
workflow: str | Callable,
arg: Any = None,
workflow_id: str | None = None,
task_queue: str | None = None,
execution_timeout: int | None = None,
run_timeout: int | None = None,
task_timeout: int | None = None,
) -> T
Execute a workflow and wait for its completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
str | Callable
|
The workflow function or workflow type name. |
required |
arg
|
Any
|
Input argument for the workflow. Defaults to None. |
None
|
workflow_id
|
str
|
Unique identifier for the workflow execution. If None, a UUID will be generated. Defaults to None. |
None
|
task_queue
|
str
|
Task queue name for workflow execution. If None, uses the default task queue. Defaults to None. |
None
|
execution_timeout
|
int
|
Maximum workflow execution time in seconds. Overrides config default. Defaults to None. |
None
|
run_timeout
|
int
|
Maximum single workflow run time in seconds. Overrides config default. Defaults to None. |
None
|
task_timeout
|
int
|
Maximum workflow task processing time in seconds. Overrides config default. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
T |
T
|
The workflow execution result. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.get_workflow_handle
abstractmethod
async
¶
Get a handle to an existing workflow execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
run_id
|
str
|
The specific run identifier within the workflow. If None, gets the latest run. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
WorkflowHandle[T, Any]: Handle to the workflow execution. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.cancel_workflow
abstractmethod
async
¶
Cancel a running workflow execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
run_id
|
str
|
The specific run identifier within the workflow. If None, cancels the latest run. Defaults to None. |
None
|
reason
|
str
|
Reason for cancellation. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.terminate_workflow
abstractmethod
async
¶
terminate_workflow(
workflow_id: str,
run_id: str | None = None,
reason: str | None = None,
) -> None
Terminate a running workflow execution immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
run_id
|
str
|
The specific run identifier within the workflow. If None, terminates the latest run. Defaults to None. |
None
|
reason
|
str
|
Reason for termination. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.signal_workflow
abstractmethod
async
¶
signal_workflow(
workflow_id: str,
signal_name: str,
arg: Any = None,
run_id: str | None = None,
) -> None
Send a signal to a running workflow execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
signal_name
|
str
|
The name of the signal to send. |
required |
arg
|
Any
|
Argument to pass with the signal. Defaults to None. |
None
|
run_id
|
str
|
The specific run identifier within the workflow. If None, signals the latest run. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.query_workflow
abstractmethod
async
¶
query_workflow(
workflow_id: str,
query_name: str,
arg: Any = None,
run_id: str | None = None,
) -> Any
Query a running workflow execution for information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
query_name
|
str
|
The name of the query to execute. |
required |
arg
|
Any
|
Argument to pass with the query. Defaults to None. |
None
|
run_id
|
str
|
The specific run identifier within the workflow. If None, queries the latest run. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The query result from the workflow. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.list_workflows
abstractmethod
async
¶
list_workflows(
query: str | None = None,
page_size: int | None = None,
next_page_token: bytes | None = None,
) -> WorkflowListResponse
List workflow executions matching the given criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
List filter query in Temporal SQL syntax. Defaults to None (no filter). |
None
|
page_size
|
int
|
Maximum number of results per page. Defaults to None (server default). |
None
|
next_page_token
|
bytes
|
Token for pagination. Defaults to None (first page). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
WorkflowListResponse |
WorkflowListResponse
|
List of workflow executions with pagination info. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.describe_workflow
abstractmethod
async
¶
Get detailed information about a workflow execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
run_id
|
str
|
The specific run identifier within the workflow. If None, describes the latest run. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
WorkflowDescription |
WorkflowDescription
|
Detailed workflow execution information. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.close
abstractmethod
async
¶
Close the Temporal client connection.
Performs cleanup of resources and closes the connection to the Temporal server. Should be called when the adapter is no longer needed.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.TemporalPort.create_schedule
abstractmethod
async
¶
create_schedule(
schedule_id: str,
workflow_class: Any,
spec: ScheduleSpec,
task_queue: str,
) -> None
Create a new schedule.
archipy.adapters.temporal.ports.TemporalPort.stop_schedule
abstractmethod
async
¶
archipy.adapters.temporal.ports.WorkerPort ¶
Interface for Temporal worker operations providing a standardized access pattern.
This interface defines the contract for Temporal worker management, ensuring consistent implementation of worker lifecycle operations. Workers are responsible for executing workflows and activities.
Implementing classes should provide concrete implementations for all methods, typically by wrapping a Temporal worker.
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.WorkerPort.start_worker
abstractmethod
async
¶
start_worker(
task_queue: str,
workflows: list[type] | None = None,
activities: list[Callable[..., Any]] | None = None,
build_id: str | None = None,
identity: str | None = None,
max_concurrent_workflow_tasks: int | None = None,
max_concurrent_activities: int | None = None,
) -> WorkerHandle
Start a Temporal worker for the specified task queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_queue
|
str
|
The task queue this worker will poll from. |
required |
workflows
|
list[type]
|
List of workflow classes to register. Defaults to None. |
None
|
activities
|
list[Callable]
|
List of activity callables to register. Defaults to None. |
None
|
build_id
|
str
|
Build identifier for worker versioning. Defaults to None. |
None
|
identity
|
str
|
Unique worker identity. If None, auto-generated. Defaults to None. |
None
|
max_concurrent_workflow_tasks
|
int
|
Maximum concurrent workflow tasks. Defaults to None (server default). |
None
|
max_concurrent_activities
|
int
|
Maximum concurrent activity tasks. Defaults to None (server default). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
WorkerHandle |
WorkerHandle
|
Handle to the started worker. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.WorkerPort.stop_worker
abstractmethod
async
¶
Stop a running Temporal worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worker_handle
|
WorkerHandle
|
Handle to the worker to stop. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.WorkerPort.shutdown_all_workers
abstractmethod
async
¶
Shutdown all workers managed by this port.
Performs graceful shutdown of all active workers, waiting for current tasks to complete before terminating.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.WorkflowHandle ¶
archipy.adapters.temporal.ports.WorkflowListResponse ¶
archipy.adapters.temporal.ports.WorkflowDescription ¶
archipy.adapters.temporal.ports.WorkerHandle ¶
Bases: ABC
Base type for worker handle.
This is an abstract base class that concrete implementations should extend. It provides a common interface for worker handle operations.
Source code in archipy/adapters/temporal/ports.py
archipy.adapters.temporal.ports.WorkerHandle.stop
abstractmethod
async
¶
Stop the worker gracefully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grace_period
|
int
|
Maximum time in seconds to wait for graceful shutdown. |
30
|
options: show_root_toc_entry: false heading_level: 3
Base¶
Base classes for Temporal workflow and activity implementations.
Base classes for Temporal workflows and activities.
This module provides base classes and utilities for implementing Temporal workflows and activities within the ArchiPy architecture, including integration with existing adapters and standardized patterns.
archipy.adapters.temporal.base.BaseWorkflow ¶
Base class for all Temporal workflows in ArchiPy.
Provides common functionality and patterns for workflow implementations, including standardized logging, error handling, and integration with ArchiPy services through activities.
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
T
|
Type of the workflow input parameter. |
required | |
R
|
Type of the workflow return value. |
required |
Source code in archipy/adapters/temporal/base.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
archipy.adapters.temporal.base.BaseWorkflow.run
async
¶
Main workflow execution method.
This method must be implemented by concrete workflow classes to define the workflow logic. It should orchestrate activities and child workflows to accomplish the business process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_input
|
T
|
The input data for the workflow. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
R |
R
|
The result of the workflow execution. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
Source code in archipy/adapters/temporal/base.py
archipy.adapters.temporal.base.BaseActivity ¶
Base class for all Temporal activities in ArchiPy.
Provides common functionality for activity implementations, including integration with your logic layer, standardized error handling, and execution hooks for cross-cutting concerns.
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
T
|
Type of the activity input parameter. |
required | |
R
|
Type of the activity return value. |
required |
Source code in archipy/adapters/temporal/base.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
archipy.adapters.temporal.base.BaseActivity.execute
async
¶
Main activity execution method with hooks.
This method provides a template for activity execution with pre/post hooks for common concerns like caching, validation, and monitoring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
activity_input
|
T
|
The input data for the activity. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
R |
R
|
The result of the activity execution. |
Raises:
| Type | Description |
|---|---|
Exception
|
Any exception that occurs during activity execution. |
Source code in archipy/adapters/temporal/base.py
archipy.adapters.temporal.base.LogicIntegratedActivity ¶
Bases: BaseActivity[T, R]
Activity base class that enforces the logic layer pattern.
This class provides helper methods that delegate to your logic instance, ensuring all business operations go through your established architecture with a single repository managing adapter access.
Source code in archipy/adapters/temporal/base.py
archipy.adapters.temporal.base.LogicIntegratedActivity.execute
async
¶
Main activity execution method with hooks.
This method provides a template for activity execution with pre/post hooks for common concerns like caching, validation, and monitoring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
activity_input
|
T
|
The input data for the activity. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
R |
R
|
The result of the activity execution. |
Raises:
| Type | Description |
|---|---|
Exception
|
Any exception that occurs during activity execution. |
Source code in archipy/adapters/temporal/base.py
archipy.adapters.temporal.base.AtomicActivity ¶
Bases: BaseActivity[T, R]
Activity base class with built-in atomic transaction support.
This class extends BaseActivity to provide direct atomic transaction support within activity execution, ensuring database consistency during activity operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logic
|
Any
|
Business logic instance with repository access. Defaults to None. |
None
|
db_type
|
str
|
Database type for atomic operations. Defaults to "postgres". |
'postgres'
|
Source code in archipy/adapters/temporal/base.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
archipy.adapters.temporal.base.AtomicActivity.execute_atomic
async
¶
Execute the activity within a database transaction.
This method wraps the entire activity execution (including pre/post hooks) within a database transaction, ensuring atomicity of all database operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
activity_input
|
T
|
The input data for the activity. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
R |
R
|
The result of the activity execution. |
Raises:
| Type | Description |
|---|---|
Exception
|
Any exception that occurs during activity execution. |
Source code in archipy/adapters/temporal/base.py
archipy.adapters.temporal.base.AtomicActivity.execute_custom_atomic_operation
async
¶
Execute a custom operation within a database transaction.
This utility method allows executing custom logic within the activity's configured atomic transaction context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation
|
Callable[[], T]
|
The operation to execute atomically. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of the operation. |
Example
Source code in archipy/adapters/temporal/base.py
archipy.adapters.temporal.base.AtomicActivity.with_db_type ¶
Create a new instance with a different database type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_type
|
str
|
The new database type ("postgres", "sqlite", or "starrocks"). |
required |
Returns:
| Type | Description |
|---|---|
AtomicActivity[T, R]
|
AtomicActivity[T, R]: New activity instance with the specified database type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid db_type is provided. |
Source code in archipy/adapters/temporal/base.py
archipy.adapters.temporal.base.AtomicActivity.execute
async
¶
Main activity execution method with hooks.
This method provides a template for activity execution with pre/post hooks for common concerns like caching, validation, and monitoring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
activity_input
|
T
|
The input data for the activity. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
R |
R
|
The result of the activity execution. |
Raises:
| Type | Description |
|---|---|
Exception
|
Any exception that occurs during activity execution. |
Source code in archipy/adapters/temporal/base.py
options: show_root_toc_entry: false heading_level: 3
Adapters¶
Concrete Temporal adapter implementing workflow and activity client operations.
Temporal adapter implementation for workflow orchestration.
This module provides concrete implementations of the Temporal port interfaces, integrating with the Temporal workflow engine while following ArchiPy patterns and conventions.
archipy.adapters.temporal.adapters.TemporalAdapter ¶
Bases: TemporalPort
Temporal workflow adapter implementing the TemporalPort interface.
This adapter provides a standardized interface for interacting with Temporal workflow orchestration services, following ArchiPy architecture patterns. It handles client connections, TLS configuration, and workflow lifecycle management.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temporal_config
|
TemporalConfig
|
Configuration settings for Temporal. If None, retrieves from global config. Defaults to None. |
None
|
Source code in archipy/adapters/temporal/adapters.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
archipy.adapters.temporal.adapters.TemporalAdapter.get_client
async
¶
Get or create the Temporal client connection.
Returns:
| Name | Type | Description |
|---|---|---|
Client |
Client
|
The Temporal client instance. |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If unable to connect to Temporal server. |
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.start_workflow
async
¶
start_workflow(
workflow: str | Callable,
arg: Any = None,
workflow_id: str | None = None,
task_queue: str | None = None,
execution_timeout: int | None = None,
run_timeout: int | None = None,
task_timeout: int | None = None,
memo: dict[str, Any] | None = None,
search_attributes: dict[str, Any] | None = None,
) -> WorkflowHandle[T, Any]
Start a workflow execution asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
str | Callable
|
The workflow function or workflow type name. |
required |
arg
|
Any
|
Input argument for the workflow. Defaults to None. |
None
|
workflow_id
|
str
|
Unique identifier for the workflow execution. If None, a UUID will be generated. Defaults to None. |
None
|
task_queue
|
str
|
Task queue name for workflow execution. If None, uses the default task queue. Defaults to None. |
None
|
execution_timeout
|
int
|
Maximum workflow execution time in seconds. Overrides config default. Defaults to None. |
None
|
run_timeout
|
int
|
Maximum single workflow run time in seconds. Overrides config default. Defaults to None. |
None
|
task_timeout
|
int
|
Maximum workflow task processing time in seconds. Overrides config default. Defaults to None. |
None
|
memo
|
dict[str, Any]
|
Non-indexed metadata for the workflow. Defaults to None. |
None
|
search_attributes
|
dict[str, Any]
|
Indexed metadata for workflow search. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
WorkflowHandle[T, Any]
|
WorkflowHandle[T, Any]: Handle to the started workflow execution. |
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.execute_workflow
async
¶
execute_workflow(
workflow: str | Callable,
arg: Any = None,
workflow_id: str | None = None,
task_queue: str | None = None,
execution_timeout: int | None = None,
run_timeout: int | None = None,
task_timeout: int | None = None,
) -> T
Execute a workflow and wait for its completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
str | Callable
|
The workflow function or workflow type name. |
required |
arg
|
Any
|
Input argument for the workflow. Defaults to None. |
None
|
workflow_id
|
str
|
Unique identifier for the workflow execution. If None, a UUID will be generated. Defaults to None. |
None
|
task_queue
|
str
|
Task queue name for workflow execution. If None, uses the default task queue. Defaults to None. |
None
|
execution_timeout
|
int
|
Maximum workflow execution time in seconds. Overrides config default. Defaults to None. |
None
|
run_timeout
|
int
|
Maximum single workflow run time in seconds. Overrides config default. Defaults to None. |
None
|
task_timeout
|
int
|
Maximum workflow task processing time in seconds. Overrides config default. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
T |
T
|
The workflow execution result. |
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.get_workflow_handle
async
¶
Get a handle to an existing workflow execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
run_id
|
str
|
The specific run identifier within the workflow. If None, gets the latest run. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
WorkflowHandle[T, Any]
|
WorkflowHandle[T, Any]: Handle to the workflow execution. |
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.cancel_workflow
async
¶
Cancel a running workflow execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
run_id
|
str
|
The specific run identifier within the workflow. If None, cancels the latest run. Defaults to None. |
None
|
reason
|
str
|
Reason for cancellation. Defaults to None. |
None
|
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.terminate_workflow
async
¶
terminate_workflow(
workflow_id: str,
run_id: str | None = None,
reason: str | None = None,
) -> None
Terminate a running workflow execution immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
run_id
|
str
|
The specific run identifier within the workflow. If None, terminates the latest run. Defaults to None. |
None
|
reason
|
str
|
Reason for termination. Defaults to None. |
None
|
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.signal_workflow
async
¶
signal_workflow(
workflow_id: str,
signal_name: str,
arg: Any = None,
run_id: str | None = None,
) -> None
Send a signal to a running workflow execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
signal_name
|
str
|
The name of the signal to send. |
required |
arg
|
Any
|
Argument to pass with the signal. Defaults to None. |
None
|
run_id
|
str
|
The specific run identifier within the workflow. If None, signals the latest run. Defaults to None. |
None
|
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.query_workflow
async
¶
query_workflow(
workflow_id: str,
query_name: str,
arg: Any = None,
run_id: str | None = None,
) -> Any
Query a running workflow execution for information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
query_name
|
str
|
The name of the query to execute. |
required |
arg
|
Any
|
Argument to pass with the query. Defaults to None. |
None
|
run_id
|
str
|
The specific run identifier within the workflow. If None, queries the latest run. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The query result from the workflow. |
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.list_workflows
async
¶
list_workflows(
query: str | None = None,
page_size: int | None = None,
next_page_token: bytes | None = None,
) -> Any
List workflow executions matching the given criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
List filter query in Temporal SQL syntax. Defaults to None (no filter). |
None
|
page_size
|
int
|
Maximum number of results per page. Defaults to None (server default). |
None
|
next_page_token
|
bytes
|
Token for pagination. Defaults to None (first page). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
List of workflow executions with pagination info. |
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.describe_workflow
async
¶
Get detailed information about a workflow execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_id
|
str
|
The unique identifier of the workflow execution. |
required |
run_id
|
str
|
The specific run identifier within the workflow. If None, describes the latest run. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Detailed workflow execution information. |
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.close
async
¶
Close the Temporal client connection.
Performs cleanup of resources and closes the connection to the Temporal server. Should be called when the adapter is no longer needed.
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.create_schedule
async
¶
create_schedule(
schedule_id: str,
workflow_class: Any,
spec: ScheduleSpec,
task_queue: str,
workflow_id: str | None = None,
schedule_policy: SchedulePolicy | None = None,
) -> None
Create a schedule for a workflow.
Source code in archipy/adapters/temporal/adapters.py
archipy.adapters.temporal.adapters.TemporalAdapter.stop_schedule
async
¶
options: show_root_toc_entry: false heading_level: 3
Runtime¶
Temporal runtime configuration and initialization utilities.
Temporal Runtime singleton for managing Runtime instances with telemetry.
This module provides a singleton class for creating and managing Temporal Runtime instances with Prometheus metrics integration.
archipy.adapters.temporal.runtime.TemporalRuntimeManager ¶
Singleton manager for Temporal Runtime instances with telemetry configuration.
This class ensures only one Runtime instance is created and reused across all Temporal clients and workers. Once created with metrics enabled, the Runtime cannot be changed (Temporal SDK limitation).
Example
Source code in archipy/adapters/temporal/runtime.py
archipy.adapters.temporal.runtime.TemporalRuntimeManager.get_runtime ¶
Get or create a Runtime with Prometheus telemetry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prometheus_enabled
|
bool
|
Whether to enable Prometheus metrics collection. |
False
|
prometheus_port
|
int
|
Port for the Prometheus metrics endpoint. |
18201
|
Returns:
| Type | Description |
|---|---|
Runtime | None
|
Runtime | None: The configured Runtime instance if metrics are enabled, None otherwise (uses default Runtime). |
Note
Once a Runtime is created with metrics enabled, it cannot be disabled or recreated on a different port due to Temporal SDK limitations. Subsequent calls will return the existing Runtime regardless of parameters.
Source code in archipy/adapters/temporal/runtime.py
archipy.adapters.temporal.runtime.TemporalRuntimeManager.reset_runtime ¶
Reset the Runtime instance.
Warning
This does NOT actually close the Runtime or release the port binding. The Temporal SDK does not support Runtime cleanup. This method only resets internal references for testing purposes. The port will remain bound until the process exits.
Source code in archipy/adapters/temporal/runtime.py
options: show_root_toc_entry: false heading_level: 3
Worker¶
Temporal worker setup for executing workflows and activities.
Worker management for Temporal workflow execution.
This module provides worker management functionality for Temporal workflow orchestration, including worker lifecycle management, task queue assignment, and integration with ArchiPy service adapters.
archipy.adapters.temporal.worker.WorkerHandle ¶
Bases: WorkerHandle
Handle for managing a Temporal worker instance.
Provides methods to control and monitor a running Temporal worker, including starting, stopping, and querying worker status.
Attributes:
| Name | Type | Description |
|---|---|---|
worker_id |
str
|
Unique identifier for this worker instance. |
task_queue |
str
|
The task queue this worker polls from. |
workflows |
list[type]
|
List of workflow types registered with this worker. |
activities |
list[Callable]
|
List of activity callables registered with this worker. |
build_id |
str | None
|
Build identifier for worker versioning. |
identity |
str | None
|
Worker identity for debugging and monitoring. |
max_concurrent_workflow_tasks |
int
|
Maximum concurrent workflow tasks. |
max_concurrent_activities |
int
|
Maximum concurrent activity tasks. |
Source code in archipy/adapters/temporal/worker.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
archipy.adapters.temporal.worker.WorkerHandle.task_queue
instance-attribute
¶
archipy.adapters.temporal.worker.WorkerHandle.workflows
instance-attribute
¶
archipy.adapters.temporal.worker.WorkerHandle.activities
instance-attribute
¶
archipy.adapters.temporal.worker.WorkerHandle.max_concurrent_workflow_tasks
instance-attribute
¶
archipy.adapters.temporal.worker.WorkerHandle.max_concurrent_activities
instance-attribute
¶
archipy.adapters.temporal.worker.WorkerHandle.is_running
property
¶
Check if the worker is currently running.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the worker is running, False otherwise. |
archipy.adapters.temporal.worker.WorkerHandle.start
async
¶
Start the worker to begin polling for tasks.
Raises:
| Type | Description |
|---|---|
WorkerConnectionError
|
If the worker fails to start. |
Source code in archipy/adapters/temporal/worker.py
archipy.adapters.temporal.worker.WorkerHandle.stop
async
¶
Stop the worker gracefully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grace_period
|
int
|
Maximum time to wait for graceful shutdown in seconds. Defaults to 30. |
30
|
Raises:
| Type | Description |
|---|---|
WorkerShutdownError
|
If the worker fails to stop gracefully. |
Source code in archipy/adapters/temporal/worker.py
archipy.adapters.temporal.worker.WorkerHandle.wait_until_stopped
async
¶
archipy.adapters.temporal.worker.WorkerHandle.get_stats ¶
Get worker statistics and status information.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Worker statistics and status. |
Source code in archipy/adapters/temporal/worker.py
archipy.adapters.temporal.worker.TemporalWorkerManager ¶
Bases: WorkerPort
Manager for Temporal worker lifecycle and operations.
This class provides a high-level interface for managing Temporal workers, including creation, configuration, and lifecycle management. It integrates with ArchiPy configuration and service patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temporal_config
|
TemporalConfig
|
Configuration settings for Temporal. If None, retrieves from global config. Defaults to None. |
None
|
Source code in archipy/adapters/temporal/worker.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | |
archipy.adapters.temporal.worker.TemporalWorkerManager.config
instance-attribute
¶
archipy.adapters.temporal.worker.TemporalWorkerManager.worker_count
property
¶
Get the number of managed workers.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of managed workers. |
archipy.adapters.temporal.worker.TemporalWorkerManager.start_worker
async
¶
start_worker(
task_queue: str,
workflows: list[type] | None = None,
activities: list[Callable[..., Any]] | None = None,
build_id: str | None = None,
identity: str | None = None,
max_concurrent_workflow_tasks: int | None = None,
max_concurrent_activities: int | None = None,
) -> WorkerHandle
Start a Temporal worker for the specified task queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_queue
|
str
|
The task queue this worker will poll from. |
required |
workflows
|
list[type]
|
List of workflow classes to register. Defaults to None. |
None
|
activities
|
list[Callable]
|
List of activity callables to register. Defaults to None. |
None
|
build_id
|
str
|
Build identifier for worker versioning. Defaults to None. |
None
|
identity
|
str
|
Unique worker identity. If None, auto-generated. Defaults to None. |
None
|
max_concurrent_workflow_tasks
|
int
|
Maximum concurrent workflow tasks. Defaults to None (server default). |
None
|
max_concurrent_activities
|
int
|
Maximum concurrent activity tasks. Defaults to None (server default). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
WorkerHandle |
WorkerHandle
|
Handle to the started worker. |
Raises:
| Type | Description |
|---|---|
WorkerConnectionError
|
If the worker fails to start. |
Source code in archipy/adapters/temporal/worker.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
archipy.adapters.temporal.worker.TemporalWorkerManager.stop_worker
async
¶
Stop a running Temporal worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worker_handle
|
WorkerHandle
|
Handle to the worker to stop. |
required |
Raises:
| Type | Description |
|---|---|
WorkerShutdownError
|
If the worker fails to stop gracefully. |
Source code in archipy/adapters/temporal/worker.py
archipy.adapters.temporal.worker.TemporalWorkerManager.shutdown_all_workers
async
¶
Shutdown all workers managed by this port.
Performs graceful shutdown of all active workers, waiting for current tasks to complete before terminating.
Raises:
| Type | Description |
|---|---|
WorkerShutdownError
|
If any worker fails to shutdown gracefully. |
Source code in archipy/adapters/temporal/worker.py
archipy.adapters.temporal.worker.TemporalWorkerManager.get_worker_stats ¶
Get statistics for all managed workers.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of worker statistics. |
archipy.adapters.temporal.worker.TemporalWorkerManager.get_worker_by_task_queue ¶
Get a worker handle by task queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_queue
|
str
|
The task queue to search for. |
required |
Returns:
| Type | Description |
|---|---|
WorkerHandle | None
|
WorkerHandle | None: Worker handle if found, None otherwise. |
Source code in archipy/adapters/temporal/worker.py
archipy.adapters.temporal.worker.TemporalWorkerManager.list_workers ¶
Get a list of all managed workers.
Returns:
| Type | Description |
|---|---|
list[WorkerHandle]
|
list[WorkerHandle]: List of worker handles. |
archipy.adapters.temporal.worker.TemporalWorkerManager.close
async
¶
Close the worker manager and all managed workers.
Performs cleanup of all resources, including stopping all workers and closing the Temporal client connection.
Source code in archipy/adapters/temporal/worker.py
options: show_root_toc_entry: false heading_level: 3