diff --git a/sentry/activities.py b/sentry/activities.py new file mode 100644 index 00000000..e968e456 --- /dev/null +++ b/sentry/activities.py @@ -0,0 +1,14 @@ +from dataclasses import dataclass +from temporalio import activity + + +@dataclass +class ComposeGreetingInput: + greeting: str + name: str + + +@activity.defn +async def compose_greeting(input: ComposeGreetingInput) -> str: + activity.logger.info("Running activity with parameter %s" % input) + return f"{input.greeting}, {input.name}!" diff --git a/sentry/worker.py b/sentry/worker.py index 1db0826b..f9d4cda0 100644 --- a/sentry/worker.py +++ b/sentry/worker.py @@ -5,37 +5,14 @@ from datetime import timedelta import sentry_sdk -from temporalio import activity, workflow +from sentry.activities import compose_greeting +from sentry.workflows import GreetingWorkflow from temporalio.client import Client from temporalio.worker import Worker from sentry.interceptor import SentryInterceptor -@dataclass -class ComposeGreetingInput: - greeting: str - name: str - - -@activity.defn -async def compose_greeting(input: ComposeGreetingInput) -> str: - activity.logger.info("Running activity with parameter %s" % input) - return f"{input.greeting}, {input.name}!" - - -@workflow.defn -class GreetingWorkflow: - @workflow.run - async def run(self, name: str) -> str: - workflow.logger.info("Running workflow with parameter %s" % name) - return await workflow.execute_activity( - compose_greeting, - ComposeGreetingInput("Hello", name), - start_to_close_timeout=timedelta(seconds=10), - ) - - async def main(): # Uncomment the line below to see logging # logging.basicConfig(level=logging.INFO) diff --git a/sentry/workflows.py b/sentry/workflows.py new file mode 100644 index 00000000..e163610e --- /dev/null +++ b/sentry/workflows.py @@ -0,0 +1,18 @@ +from temporalio import activity, workflow +from dataclasses import dataclass +from datetime import timedelta +# Import our activity and param class, passing it through the sandbox +with workflow.unsafe.imports_passed_through(): + from sentry.activities import ComposeGreetingInput, compose_greeting + + +@workflow.defn +class GreetingWorkflow: + @workflow.run + async def run(self, name: str) -> str: + workflow.logger.info("Running workflow with parameter %s" % name) + return await workflow.execute_activity( + compose_greeting, + ComposeGreetingInput("Hello", name), + start_to_close_timeout=timedelta(seconds=10), + )