Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
19 changes: 19 additions & 0 deletions reauth_after_risk_event/starter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import asyncio
from datetime import timedelta
from temporalio.client import Client

async def main():
client = await Client.connect("localhost:7233")

result = await client.start_workflow(
"ReauthenticationAfterRiskEventWorkflow",
"user-123", # user_id
id="reauth-workflow-user-123",
task_queue="reauth-task-queue",
run_timeout=timedelta(minutes=1), # Correct timeout usage
)

print(f"Started workflow. Run ID: {result.id}")

if __name__ == "__main__":
asyncio.run(main())
17 changes: 17 additions & 0 deletions reauth_after_risk_event/worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import asyncio
from temporalio.worker import Worker
from temporalio.client import Client
from workflow import ReauthenticationAfterRiskEventWorkflow

async def main():
client = await Client.connect("localhost:7233")
worker = Worker(
client,
task_queue="reauth-task-queue",
workflows=[ReauthenticationAfterRiskEventWorkflow],
)
print("Worker started.")
await worker.run()

if __name__ == "__main__":
asyncio.run(main())
29 changes: 29 additions & 0 deletions reauth_after_risk_event/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from datetime import timedelta
from temporalio import workflow

# Signal to be sent when user completes reauthentication
@workflow.defn
class ReauthenticationAfterRiskEventWorkflow:
def __init__(self):
self.reauthenticated = False

@workflow.signal
async def complete_reauthentication(self):
self.reauthenticated = True

@workflow.run
async def run(self, user_id: str, timeout_minutes: int = 10) -> str:
workflow.logger.info(f"Started reauth workflow for user: {user_id}")

# Wait for signal or timeout
try:
await workflow.wait_condition(
lambda: self.reauthenticated,
timeout=timedelta(minutes=timeout_minutes)
)
except TimeoutError:
workflow.logger.warn("Timeout waiting for reauthentication")
return "failed_timeout"

workflow.logger.info("User successfully reauthenticated")
return "success"