Repository navigation
Expand file tree
/
Copy pathtest_drivers.py
More file actions
59 lines (50 loc) · 1.88 KB
/
Copy pathtest_drivers.py
File metadata and controls
59 lines (50 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
from temporalio import workflow
from temporalio.common import RetryPolicy
from datetime import timedelta
from typing import Optional
with workflow.unsafe.imports_passed_through():
from activities import (
IngestInput,
ingest_documents_activity,
ContextualizeInput,
contextualize_activity,
)
from config import settings
def _activity_retry_policy(max_attempts: Optional[int] = None) -> RetryPolicy:
return RetryPolicy(
initial_interval=timedelta(seconds=settings.retries.initial_interval),
backoff_coefficient=settings.retries.backoff_coefficient,
maximum_interval=timedelta(seconds=settings.retries.maximum_interval),
maximum_attempts=max_attempts or settings.retries.max_attempts,
non_retryable_error_types=[
"ContextualizationError",
"RetrievalError",
"GenerationError",
"EmbeddingError",
"IngestionError",
],
)
@workflow.defn
class AcceptanceIngestDriverWorkflow:
"""Short-lived driver workflow used by acceptance tests to schedule an
ingest_documents_activity. Temporal 1.32+ does not allow scheduling a raw
activity outside a workflow, so we use this thin wrapper.
"""
@workflow.run
async def run(self, arg: IngestInput) -> dict:
return await workflow.execute_activity(
ingest_documents_activity,
arg,
start_to_close_timeout=timedelta(seconds=300),
retry_policy=_activity_retry_policy(),
)
@workflow.defn
class AcceptanceContextualizeDriverWorkflow:
@workflow.run
async def run(self, arg: ContextualizeInput) -> str:
return await workflow.execute_activity(
contextualize_activity,
arg,
start_to_close_timeout=settings.timeouts.contextualize_td,
retry_policy=RetryPolicy(maximum_attempts=1),
)