This sample shows how to keep workers running while workflows are present on a given task queue while using task queue routing as a versioning strategy for new workflow executions. Using this strategy it is possible to keep old workers alive only so long as work is available for them to do, virtually eliminating the need to maintain old code paths.
This strategy has tradeoffs which are not present in other versioning strategies. It makes the maintaining of old code version generally unnecessary, but introduces some unique constraints.
- If using this strategy with Kubernetes rolling deployments it is important to recognize that during a rollout there is a sharing of pods between two task queues which may mean there is increased end-to-end latency for workflow executions on the old task queue
- Use of Workflow Queries IS NOT generally safe—as old workers/versions will not be guaranteed to be available for the purpose of Querying once all workflow executions on a task queue have completed
- This strategy complicates the use of workflow replay testing, as histories are task queue specific. That said, replays do not apply to this strategy except by Workflow Query.
- Any need to roll back to an old code version implies getting old code out of version control, switching task queues, and redeploying. This is not unique to Temporal, though other strategies imply maintaining old code/workers so switching back is theoretically simpler.
temporal server start-dev
to start Temporal Server.npm install
to install dependencies.npm run start.server
to start the server.- Visit
localhost:8000
to start a workflow - Visit your local Temporal server frontend (usually
localhost:8233
) to verify the workflow started - Visit
localhost:8000
to start a workflow - Before the workflow ends (50 seconds-you can change this to be as long as you like in
activities.ts:4
) modify:- The port on
server.ts:10
(e.g. 8001 instead of 8000) - Uncomment
workflows.ts:11
to add a breaking change to the workflow definition - Change
taskqueue.txt:1
to any new value (e.g.my-task-queue-1
)
- The port on
- Visit
localhost:8000
to start a new workflow—it will start on the new task queue declared in Step 7.3 - In a new shell run
npm run start.server
starting a new worker on the new task queue - Visit
localhost:{portDeclaredInStep7.1}
to start a new workflow - All previous workflow executions on the original task queue will end, resulting in the shutdown of the original worker process
- You can still visit the
localhost:{portDeclaredInStep7.1}
to start new workflows on the new worker process