Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[projection] Pass Context values from Trigger down to the Job #256

Open
bounoable opened this issue Jan 23, 2025 · 0 comments
Open

[projection] Pass Context values from Trigger down to the Job #256

bounoable opened this issue Jan 23, 2025 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@bounoable
Copy link
Contributor

When triggering a projection schedule, the values provided with the Context are not available in the projection.Job (which is also a Context). This is because the projection schedules create a fresh Context for each projection job, and the Context passed to Schedule.Trigger() is only used to be able to cancel the trigger itself (not the projection job).

If projection jobs provided the values from the trigger context, it would be possible to provide dynamic options to a projection job.

Example

package example

import (
  "context"
  "time"

  "github.com/modernice/goes/projection"
  "github.com/modernice/goes/projection/schedule"
)

func example() {
  s := schedule.Continuously(...) // setup the projection schedule
  go s.Subscribe(context.Background(), applyJob)

  // wait a bit, then trigger the projection
  time.Sleep(3*time.Second)
  
  ctx := context.WithValue(context.Background(), "key", "value")

  s.Trigger(ctx)
}

func applyJob(ctx projection.Job) error {
  v := ctx.Value("key") // <- this currently returns null, should return "value"

  return nil
}
@bounoable bounoable added enhancement New feature or request good first issue Good for newcomers labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant