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

Faktory sequential jobs > 2 documentation question #488

Open
profsmallpine opened this issue Nov 5, 2024 · 1 comment
Open

Faktory sequential jobs > 2 documentation question #488

profsmallpine opened this issue Nov 5, 2024 · 1 comment

Comments

@profsmallpine
Copy link

I am wondering if you can have multiple sequential jobs. Given that a success callback requires a job and not a batch, how would you handle sequences > 2?

	err := s.Pool.With(func(c *client.Client) error {
		job3 := client.NewJob("job-3", arg3)
		job2 := client.NewJob("job-2", arg2)
		job1 := client.NewJob("job-1", arg1)

		b := client.NewBatch(c)
		b.Success = job2
		err := b.Jobs(func() error {
			return b.Push(job1)
		})

		return err
	})

	return err

I don't see how I would tell job3 to execute after job2 completes. After reading https://github.com/contribsys/faktory/wiki/Ent-Batches, I assumed this was possible but can't seem to figure out the right syntax (if it's possible). Any guidance here?

@mperham
Copy link
Collaborator

mperham commented Nov 5, 2024

That's the purpose of nested batches. You have a parent batch A with child batch B full of jobs. When those jobs are done, B's success callback fires; the callback opens the parent batch and adds a new child batch C with the next sequential step's jobs.

Admittedly this process is poorly documented. Check out these code snippets and if you get something that works for you, I'd be happy to add any code example to the wiki to help people in the future.

https://github.com/contribsys/faktory_worker_go/blob/b190f42786c86b871b997314951e604468f1b39a/test/main.go#L174

func (c *Client) BatchOpen(bid string) (*Batch, error) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants