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

Batch retry inside of super job #22

Open
j-mcnally opened this issue Jun 13, 2014 · 2 comments
Open

Batch retry inside of super job #22

j-mcnally opened this issue Jun 13, 2014 · 2 comments

Comments

@j-mcnally
Copy link

If an item in a batch fails and is retried, the batch finalizes and next task is run before the batch completes.

Superworker.create(:ImageImportSuperWorker, :staging_image_ids, :valid_only, :started_at, :staging_image_group_id) do
  batch staging_image_ids: :staging_image_id do
    ImageImportWorker :staging_image_id, :valid_only
  end
  FinalizeImageImportWorker :staging_image_group_id, :valid_only, :started_at
end

In the example FinalizeImageImportWorker can be called before all the batch ImageImportWorkers are actually done, if an ImageImportWorker is retried.

@j-mcnally
Copy link
Author

The work around to this is to disable the child worker retries completely and keep retrying on the same worker/thread.

The following module which can be included in sidekiq workers does the trick

module Sidekiq
  module RetryManually
    def with_retry(count=10, &block)
      retries = 0
      begin
        yield
      rescue Exception => e
        if (retries <= count)
          retries += 1
          sleep (retries * 1)
          retry
        else
          puts "Sidekiq Failed after #{count} retries::: #{e.inspect}"
          raise e
        end
      end
    end
  end
end

and can be called around the perform code

  def perform(staging_image_id, valid_only, time=0, staging_group=0)
    with_retry 5 do
      staging_image_group = nil
      StagingImage.find(staging_image_id).import!
    end
  end

@brodock
Copy link

brodock commented Oct 23, 2015

does it still apply?

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