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

Support Sidekiq Pro super_fetch #175

Conversation

mnovelo
Copy link
Contributor

@mnovelo mnovelo commented Jan 14, 2024

Distilling the discussions in this issue and the work in this fork, this adds support for Sidekiq Pro's super_fetch for v1 of sidekiq-throttled and v7.x of Sidekiq Pro.

Copy link

codecov bot commented Jan 14, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (6294b2b) 98.94% compared to head (e60d61e) 97.47%.
Report is 1 commits behind head on improve-composability-of-patches.

❗ Current head e60d61e differs from pull request most recent head 59862d1. Consider uploading reports for the commit 59862d1 to get more accurate results

Files Patch % Lines
lib/sidekiq/throttled/patches/super_fetch.rb 64.70% 6 Missing ⚠️
Additional details and impacted files
@@                         Coverage Diff                          @@
##           improve-composability-of-patches     #175      +/-   ##
====================================================================
- Coverage                             98.94%   97.47%   -1.47%     
====================================================================
  Files                                    18       19       +1     
  Lines                                   378      396      +18     
  Branches                                 52       54       +2     
====================================================================
+ Hits                                    374      386      +12     
- Misses                                    4       10       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ixti ixti requested review from freemanoid and ixti January 15, 2024 01:42
Comment on lines 36 to 42
if work.respond_to?(:local_queue)
# if a SuperFetch UnitOfWork, SuperFetch will requeue it using lpush
work.requeue
else
# Fallback to BasicFetch behavior
redis { |conn| conn.lpush(work.queue, work.job) }
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been thinking about requeue logic in context of #150 and I think default logic should simply take unit_of_work's job and push it using Sidekiq::Client.push(message)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way, that can be done separately (when I will have time to work on #150)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to change the behavior separately, keeping it in sync with the behavior for BasicFetch.

One caveat with using Sidekiq::Client.push(message) instead of conn.lpush is that it will overwrite the original enqueued_at https://github.com/sidekiq/sidekiq/blob/7df28434f03fa1111e9e2834271c020205369f94/lib/sidekiq/client.rb#L260

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original enqueued_at value isn't really important to us though, so we'd be fine if it got replaced with each throttle

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original enqueued_at value isn't really important to us though, so we'd be fine if it got replaced with each throttle

It might be important for sidekiq-pro expiring jobs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I missed that it replaces enqueued_at. Let's keep it as is - as long as we can guarantee that it won't break a reliable (or whatever it is called) client. In either case, we need to call acknowledgement so that the job gets removed from the temporary queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requeue method of the SuperFetch UnitOfWork takes care of removing from the temporary queue, so I'll add that it does in a comment.

@freemanoid the expiring jobs middleware doesn't use enqueued_at

lib/sidekiq/throttled/patches/super_fetch.rb Outdated Show resolved Hide resolved
lib/sidekiq/throttled/patches/super_fetch.rb Outdated Show resolved Hide resolved
lib/sidekiq/throttled/patches/super_fetch.rb Show resolved Hide resolved
Comment on lines 36 to 42
if work.respond_to?(:local_queue)
# if a SuperFetch UnitOfWork, SuperFetch will requeue it using lpush
work.requeue
else
# Fallback to BasicFetch behavior
redis { |conn| conn.lpush(work.queue, work.job) }
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original enqueued_at value isn't really important to us though, so we'd be fine if it got replaced with each throttle

It might be important for sidekiq-pro expiring jobs.

ixti added a commit that referenced this pull request Jan 16, 2024
@ixti ixti mentioned this pull request Jan 16, 2024
@ixti
Copy link
Owner

ixti commented Jan 16, 2024

@mnovelo I've extracted Ruby-3.3 support into a separate PR: #176 to avoid scope creep in this one.

spec/support/sidekiq.rb Outdated Show resolved Hide resolved
ixti added a commit that referenced this pull request Jan 16, 2024
mnovelo and others added 3 commits January 16, 2024 11:33
Co-authored-by: Alexey Zapparov <alexey@zapparov.com>
Signed-off-by: Mauricio Novelo <mauricio.novelo@gmail.com>
@mnovelo mnovelo changed the base branch from main to improve-composability-of-patches January 16, 2024 17:11
@ixti ixti deleted the branch ixti:improve-composability-of-patches January 16, 2024 17:36
@ixti ixti closed this Jan 16, 2024
@ixti
Copy link
Owner

ixti commented Jan 16, 2024

o_O I swear I was not closing this PR

@ixti
Copy link
Owner

ixti commented Jan 16, 2024

Just merged the improve-composability-of-patches branch.

@ixti
Copy link
Owner

ixti commented Jan 16, 2024

@mnovelo please rebase this PR on main branch.

@ixti
Copy link
Owner

ixti commented Jan 16, 2024

GH does not allow me to even reopen this PR. O_o what the...

@mnovelo
Copy link
Contributor Author

mnovelo commented Jan 16, 2024

Weird! I re-opened against the main branch

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

Successfully merging this pull request may close these issues.

None yet

3 participants