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

enqueue-multi compatibility fixes #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

onyxraven
Copy link
Member

@onyxraven onyxraven commented Aug 19, 2024

Add flag that enables/disables the batch enqueue mode for delayed jobs.

The batch enqueue mode causes issues because it starts a multi/pipeline, but this breaks a number of other plugins that rely on doing Redis work within that enqueue window.

The current approach is to make the batch behavior opt-in, with a flag. The documentation can then lay out the compatibility risks.

References:

This PR also updates compatibility with ruby 3.x, and associated dependencies, lints, deprecations, etc. I realize this creates a bigger PR with a few 'style' type changes, but it helped me immensely when working to resolve this.

Compatibility integration tests with other gems (just resque-lock-timeout for now) exist in this PR - this helps prove out the fix. I hope to keep this up to date with any changes.

@onyxraven onyxraven force-pushed the enqueue-multi-rollback branch 2 times, most recently from 354d46d to 4337268 Compare August 19, 2024 17:14
@onyxraven onyxraven force-pushed the enqueue-multi-rollback branch 3 times, most recently from 3feb932 to 3686b62 Compare October 15, 2024 15:51
- "3.0"
- "3.1"
- "3.2"
- "3.3"
Copy link
Member Author

@onyxraven onyxraven Oct 15, 2024

Choose a reason for hiding this comment

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

Updated to later released ruby

- "~> 5.x"
- "~> 3.3"
- "~> 4.8"
- "~> 5.2"
Copy link
Member Author

@onyxraven onyxraven Oct 15, 2024

Choose a reason for hiding this comment

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

may update the matrix again, but trying to ensure this is relatively complete, with ruby 3.0+ supporting versions and in-use redis versions. will need to look at the gemspec constraints too

AllCops:
TargetRubyVersion: 3.0
Copy link
Member Author

@onyxraven onyxraven Oct 15, 2024

Choose a reason for hiding this comment

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

simplified/resolved rubocop due to updates, and supporting ruby 3.

I'm happy to remove the todo (since it covers stuff not in the below Include)

@@ -1,4 +1,3 @@
# vim:fileencoding=utf-8
Copy link
Member Author

Choose a reason for hiding this comment

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

this was in every file and is now a default cop, so cleaned up. IIRC its not necessary.

@@ -204,25 +202,36 @@ def enqueue_next_item(timestamp)
item
end

def batch_delayed_items?
Copy link
Member Author

Choose a reason for hiding this comment

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

This starts the refactor that revives the 'non batched' mode by deciding if batching is appropriate

log "queued batch of #{actual_batch_size} jobs" if actual_batch_size != -1
else
item = enqueue_next_item(timestamp)
actual_batch_size = item.nil? ? 0 : 1
Copy link
Member Author

Choose a reason for hiding this comment

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

non batched version

def delayed_requeue_batch_size
@delayed_requeue_batch_size ||= \
ENV['DELAYED_REQUEUE_BATCH_SIZE'].to_i if environment['DELAYED_REQUEUE_BATCH_SIZE']
@delayed_requeue_batch_size ||= 100
end

attr_writer :enable_delayed_requeue_batches

def enable_delayed_requeue_batches
Copy link
Member Author

Choose a reason for hiding this comment

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

config to enable batches (off by default)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to reversing this - and making on by default to coincide with the latest behavior of the gem.

@@ -1,27 +1,26 @@
# vim:fileencoding=utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
Copy link
Member Author

Choose a reason for hiding this comment

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

rubocop updates

require_relative 'test_helper'

def assert_resque_key_exists?(key)
Copy link
Member Author

Choose a reason for hiding this comment

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

better support for deprecations on redis

@@ -383,60 +390,140 @@
assert_equal(1, Resque.delayed_timestamp_peek(t, 0, 3).length)
end

test 'enqueue_delayed_items_for_timestamp enqueues jobs in 2 batches' do
t = Time.now + 60
context 'non-batch delayed item queue' do
Copy link
Member Author

Choose a reason for hiding this comment

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

test for batch v non batch

gem 'racc'
gem 'rubocop', '~> 1.4'
gem 'rubocop-minitest'
gem 'rubocop-rake'
Copy link
Member Author

Choose a reason for hiding this comment

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

moved development dependencies into the gemfile

def delayed_requeue_batch_size
@delayed_requeue_batch_size ||= \
ENV['DELAYED_REQUEUE_BATCH_SIZE'].to_i if environment['DELAYED_REQUEUE_BATCH_SIZE']
@delayed_requeue_batch_size ||= 100
end

attr_writer :enable_delayed_requeue_batches

def enable_delayed_requeue_batches
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to reversing this - and making on by default to coincide with the latest behavior of the gem.

@@ -383,60 +391,115 @@
assert_equal(1, Resque.delayed_timestamp_peek(t, 0, 3).length)
end

test 'enqueue_delayed_items_for_timestamp enqueues jobs in 2 batches' do
t = Time.now + 60
context "non-batch delayed item queue" do
Copy link
Member Author

Choose a reason for hiding this comment

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

tests to ensure both batch and non-batch work properly

@@ -307,7 +307,7 @@ module Test
test 'redirects to overview' do
post '/delayed/cancel_now'
assert last_response.status == 302
assert last_response.header['Location'].include? '/delayed'
assert last_response.headers['Location'].include? '/delayed'
Copy link
Member Author

Choose a reason for hiding this comment

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

updates to new rubies.

Comment on lines +404 to +407
teardown do
Resque::Scheduler.enable_delayed_requeue_batches = batch_enabled
Resque::Scheduler.delayed_requeue_batch_size = batch_size
end

Choose a reason for hiding this comment

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

Non-blocking, I'm not sure I understand the need for this teardown step, more just understanding the spec. Shouldnt these be dumped between runs?

Copy link

@lebeerman lebeerman left a comment

Choose a reason for hiding this comment

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

I can understand both sides re: default behavior. Opt-in for batching seems ok to me.

Copy link

@physik932 physik932 left a comment

Choose a reason for hiding this comment

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

I don't know a ton but love the thoroughness and updates, and the separate testing repo with matrix compatibility for different versions ✨

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.

3 participants