I have the following Temporal workflow, written in Python:
@workflow.defn
class YourSchedulesWorkflow:
@workflow.run
async def run(self, name: str) -> str:
//call javascript activity
I have a part of code written already in JavaScript, so I want to call that JavaScript code as an activity, from my Python workflow. How do I do this?
From Temporal’s point of view, scheduling an activity only requires the activity's name (which we formally call the "activity type") and its task queue; the Temporal server itself doesn't "need" the activity function, nor care in which language is it coded.
The easiest way for your Python workflow to invoke a TypeScript activity is therefore to simply provide the correct activity type, as a string, to the
execute_activityfunction, as well as the task queue name (plus any other args/options you would otherwise want to pass). From the workflow's perspective, it makes no difference that the activity is implemented in a different language, except for the fact that it can't benefit from type safety checks that having an actual function definition allows.For example, you might do this in your workflow:
and then, start a TypeScript worker listening on task queue "typescript-activities", with the following activity:
Alternatively, it is also possible to define a stub function on your workflow side, to make cross-language activity calls looks more like regular, same-language activity calls. For example:
A few things to consider: