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

ability to switch to the ibotta-gem #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test-scheduler-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ on:
push:
branches: [$default-branch]
pull_request:
workflow_dispatch:
jobs:
test-scheduler-lock:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -40,7 +41,7 @@ jobs:
resque-lock-timeout-version:
- "latest"
- "https://github.com/Ibotta/[email protected]"
- "https://github.com/Ibotta/resque-lock-timeout.git@tests-with-scheduler"
- "ibotta-resque-lock-timeout;https://github.com/Ibotta/resque-lock-timeout.git@v0.5.1"
exclude:
# resque-scheduler (= 4.3.0) depends on redis (~> 3.3)
- redis-version: "~> 4.8"
Expand Down
21 changes: 16 additions & 5 deletions scheduler-lock/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,28 @@ else
gem "resque-scheduler", *versions
end

case resque_lock_timeout_version = ENV.fetch("RESQUE_LOCK_TIMEOUT_VERSION", "latest")
resque_lock_timeout_version = ENV.fetch("RESQUE_LOCK_TIMEOUT_VERSION", "latest")
capture_resque_lock_timeout = resque_lock_timeout_version.split(";", 2)
resque_lock_timeout_gem = if capture_resque_lock_timeout[1]
resque_lock_timeout_version = capture_resque_lock_timeout[1]
capture_resque_lock_timeout[0]
else
"resque-lock-timeout"
end
puts "resque_lock_timeout_gem: #{resque_lock_timeout_gem}"
puts "resque_lock_timeout_version: #{resque_lock_timeout_version}"

case resque_lock_timeout_version
when "master"
gem "resque-lock-timeout", git: "https://github.com/Ibotta/resque-lock-timeout.git"
gem resque_lock_timeout_gem, git: "https://github.com/Ibotta/resque-lock-timeout.git"
when /^git:/, /^https:/
repo, ref = resque_lock_timeout_version.split("@", 2)
gem "resque-lock-timeout", git: repo, ref: ref
gem resque_lock_timeout_gem, git: repo, ref: ref
when "latest"
gem "resque-lock-timeout"
gem resque_lock_timeout_gem
else
versions = resque_lock_timeout_version.split(",")
gem "resque-lock-timeout", *versions
gem resque_lock_timeout_gem, *versions
end

gem "rake"
Expand Down
38 changes: 11 additions & 27 deletions scheduler-lock/test/delayed_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,30 @@ def test_delayed_item_enqueue
# assert that the active queue has the lonely job
if scheduler_version_compare("< 4.9")
assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob)))
elsif Resque::Scheduler::VERSION.end_with?("-ibotta")
assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob)))
else
# this is asserting that > 4.9 "fails" without the patch
assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob)))
end
end
end

if Resque::Scheduler::VERSION.end_with?("-ibotta")
if scheduler_version_compare(">= 4.11")
class LockBatchOffTest < Minitest::Test
def setup
@batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches
@batch_enabled = Resque::Scheduler.disable_delayed_requeue_batches
@batch_size = Resque::Scheduler.delayed_requeue_batch_size

$success = $lock_failed = $lock_expired = $enqueue_failed = 0
Resque::Scheduler.quiet = true
Resque.redis.redis.flushall
@worker = Resque::Worker.new(:test)

Resque::Scheduler.enable_delayed_requeue_batches = false
Resque::Scheduler.disable_delayed_requeue_batches = true
Resque::Scheduler.delayed_requeue_batch_size = 1
end

def teardown
Resque::Scheduler.enable_delayed_requeue_batches = @batch_enabled
Resque::Scheduler.disable_delayed_requeue_batches = @batch_enabled
Resque::Scheduler.delayed_requeue_batch_size = @batch_size
end

Expand All @@ -72,34 +70,27 @@ def test_delayed_item_enqueue
assert_equal(0, Resque.delayed_timestamp_size(t))

# assert that the active queue has the lonely job
if scheduler_version_compare("< 4.9")
assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob)))
elsif Resque::Scheduler::VERSION.end_with?("-ibotta")
# should act like before
assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob)))
else
# this is asserting that > 4.9 "fails" without the patch
assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob)))
end
# should act like before, and have an item queued
assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob)))
end
end

class LockBatchOnTest < Minitest::Test
def setup
@batch_enabled = Resque::Scheduler.enable_delayed_requeue_batches
@batch_enabled = Resque::Scheduler.disable_delayed_requeue_batches
@batch_size = Resque::Scheduler.delayed_requeue_batch_size

$success = $lock_failed = $lock_expired = $enqueue_failed = 0
Resque::Scheduler.quiet = true
Resque.redis.redis.flushall
@worker = Resque::Worker.new(:test)

Resque::Scheduler.enable_delayed_requeue_batches = true
Resque::Scheduler.disable_delayed_requeue_batches = false
Resque::Scheduler.delayed_requeue_batch_size = 100
end

def teardown
Resque::Scheduler.enable_delayed_requeue_batches = @batch_enabled
Resque::Scheduler.disable_delayed_requeue_batches = @batch_enabled
Resque::Scheduler.delayed_requeue_batch_size = @batch_size
end

Expand All @@ -115,15 +106,8 @@ def test_delayed_item_enqueue
Resque::Scheduler.enqueue_delayed_items_for_timestamp(t)
assert_equal(0, Resque.delayed_timestamp_size(t))

# assert that the active queue has the lonely job
if scheduler_version_compare("< 4.9")
assert_equal(1, Resque.size(Resque.queue_from_class(LonelyJob)))
elsif Resque::Scheduler::VERSION.end_with?("-ibotta")
assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob)))
else
# this is asserting that > 4.9 "fails" without the patch
assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob)))
end
# using batches, so the lonely job gets rejected "fail"
assert_equal(0, Resque.size(Resque.queue_from_class(LonelyJob)))
end
end

Expand Down