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

How do I add jobs to an existing batch? #1337

Closed
gap777 opened this issue Apr 25, 2024 · 7 comments
Closed

How do I add jobs to an existing batch? #1337

gap777 opened this issue Apr 25, 2024 · 7 comments

Comments

@gap777
Copy link
Contributor

gap777 commented Apr 25, 2024

I'm having trouble understanding how to add new jobs to an existing batch.

Here's what I'm doing:

  1. creating a batch
GoodJobs::Batch.new(metadata: 'foo').enqueue { TestJob.perform_later(bar: 1) } 
  1. some time later, I'm adding a new job to the batch:
GoodJobs::Batch.find(that_batch_id).enqueue { TestJob.perform_later(bar: 2) }
  1. I see my jobs performing wonderfully.

  2. I see a batch created

  3. There are no jobs in my batch (neither in Batch panel in GoodJobs dashboard, or is the GoodJobs::Job#batch_id set)

Can you advise on how to do this?

@bensheldon
Copy link
Owner

That's weird! I just tried this exploratory test and it passes:

describe 'adding to an existing batch' do
  it 'will add jobs to the existing batch' do
    batch = GoodJob::Batch.new(metadata: 'foo')
    batch.enqueue { TestJob.perform_later }

    GoodJob::Batch.find(batch.id).enqueue { TestJob.perform_later }

    batch = GoodJob::Batch.find(batch.id)
    expect(batch.active_jobs.count).to eq 2
  end
end

Have you done anything to the preserve_job_records configuration?

@gap777
Copy link
Contributor Author

gap777 commented Apr 25, 2024

Hmmm.....
I have a config initializer:

Rails.application.configure do
  config.good_job.preserve_job_records = true

Also, maybe of note, I am trying to test this using the Rails test job adapter.

Finally, this doesn't work outside of the test (in a manual integration test) either.

@bensheldon
Copy link
Owner

Also, maybe of note, I am trying to test this using the Rails test job adapter.

That's it ☝ (or at least one issue). Batches can only batch jobs that are enqueued to GoodJob.

That makes me think I could at least add a logger to the Batch job extension to log on enqueue like "This job was enqueued within a batch capture but not to the GoodJob Adapter; the job will not appear in the batch."

@gap777
Copy link
Contributor Author

gap777 commented Apr 25, 2024

That seems good.

@bensheldon
Copy link
Owner

I just opened #1339 with a warning message. Could you try that locally and see if it helps debug better?

@gap777
Copy link
Contributor Author

gap777 commented Apr 26, 2024

Thank you!

@gap777 gap777 closed this as completed Apr 26, 2024
@bensheldon
Copy link
Owner

I just released those debug messages in https://github.com/bensheldon/good_job/releases/tag/v3.28.2

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

No branches or pull requests

2 participants