fatkodima / sidekiq-iteration

Make your long-running sidekiq jobs interruptible and resumable.
https://rubydoc.info/gems/sidekiq-iteration
MIT License
270 stars 8 forks source link

Fix storing run metadata when the job fails for sidekiq < 6.5.2 #2

Closed fatkodima closed 1 year ago

fatkodima commented 1 year ago

Closes #1.

@mperham Can you please suggest how can I store some additional data to the job when it is retried without the need to override process_retry (see this PR changes)? Currently, sidekiq directly pushed the failed job to the retry queue - https://github.com/mperham/sidekiq/blob/cc2a07d45e8621aaac886290d397968aa2bc2cb6/lib/sidekiq/job_retry.rb#L187-L189 Or I am missing something?

mperham commented 1 year ago

Sidekiq jobs are meant to be idempotent. Doesn't the requirement to store job execution state mean that the job is inherently not idempotent?

You could use middleware and store your data in Redis.

fatkodima commented 1 year ago

Thank you for the response!

You could use middleware and store your data in Redis.

This is the approach I was thinking originally to implement, but decided to go with the approach used in the original gem that this gem is based on - https://github.com/Shopify/job-iteration/blob/bd6e7aa28cf9030caa99f3bd0582f18fbf7e7873/lib/job-iteration/iteration.rb#L106-L112

I will revisit the approach if it will cause more problems down the road.

mperham commented 1 year ago

Sidekiq allows middleware to mutate the job payload for the current invocation but does not persist those changes. I guess that's your issue, you want to persist your mutations to the job payload?

fatkodima commented 1 year ago

I guess that's your issue, you want to persist your mutations to the job payload?

Yes.