This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
Replies: 2 comments 4 replies
-
I'll upload a helloworld in a bit. |
Beta Was this translation helpful? Give feedback.
2 replies
-
import asyncio
import sys
import logging
from datetime import timedelta
from temporal.activity_method import activity_method
from temporal.workerfactory import WorkerFactory
from temporal.workflow import workflow_method, Workflow, WorkflowClient
logging.basicConfig(level=logging.INFO)
TASK_QUEUE = "HelloActivity-python-tq"
DOMAIN = "default"
# Activities Interface
class GreetingActivities:
@activity_method(task_queue=TASK_QUEUE, schedule_to_close_timeout=timedelta(seconds=1000))
def compose_greeting(self, greeting: str, name: str) -> str:
raise NotImplementedError
# Activities Implementation
class GreetingActivitiesImpl:
def compose_greeting(self, greeting: str, name: str):
return greeting + " " + name + "!"
# Workflow Interface
class GreetingWorkflow:
@workflow_method(task_queue=TASK_QUEUE)
async def get_greeting(self, name: str) -> str:
raise NotImplementedError
# Workflow Implementation
class GreetingWorkflowImpl(GreetingWorkflow):
def __init__(self):
self.greeting_activities: GreetingActivities = Workflow.new_activity_stub(GreetingActivities)
pass
async def get_greeting(self, name):
return await self.greeting_activities.compose_greeting("Hello", name)
async def client_main():
client = WorkflowClient.new_client(namespace=DOMAIN)
greeting_workflow: GreetingWorkflow = client.new_workflow_stub(GreetingWorkflow)
result = await greeting_workflow.get_greeting("Python")
print(result)
if __name__ == '__main__':
factory = WorkerFactory("localhost", 7233, DOMAIN)
worker = factory.new_worker(TASK_QUEUE)
worker.register_activities_implementation(GreetingActivitiesImpl(), "GreetingActivities")
worker.register_workflow_implementation_type(GreetingWorkflowImpl)
factory.start()
asyncio.run(client_main())
print("Stopping workers....")
worker.stop()
print("Workers stopped...")
sys.exit(0) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
simkimsia
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Beta Was this translation helpful? Give feedback.
All reactions