coinbase / temporal-ruby

Ruby SDK for Temporal
Apache License 2.0
238 stars 89 forks source link

Add header propagation and workflow middleware. #226

Closed markchua closed 1 year ago

markchua commented 1 year ago

This change adds the following changes and addresses https://github.com/coinbase/temporal-ruby/issues/225:

  1. Workflow middleware This is configured on a worker similar to workflow_task and acitvity middleware (worker.add_workflow_middleware(middleware). Workflow middleware gets the workflow metadata which contains headers, and can be used to extract things out of the headers. Activities already have this support via the activity middleware.

  2. Header propagation (inject into outgoing headers) This is configured on the temporal configuration (c.add_header_propagator(propagator)). The propagator is for outgoing headers- so you want to inject into the headers. A propagator is just a class that implements def inject!(header) that modifies header in place and does not return anything.

Tests have been added/amended as necessary.

The original issue recommended adding metadata to the workflow task but upon closer inspection that was not really feasible and instead was replaced with adding middleware for the workflow.