Skip to content

Commit

Permalink
Use Sidekiq::Component for Enqueuer (#18)
Browse files Browse the repository at this point in the history
* Use Sidekiq::Component for Enqueuer

Fixes #17

* Initialize earlier
  • Loading branch information
adamniedzielski authored Jun 14, 2024
1 parent dcfa2b3 commit b45c6e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/sidekiq/staged_push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def self.enable!
Sidekiq.default_job_options["client_class"] = Sidekiq::StagedPush::Client
Sidekiq::JobUtil::TRANSIENT_ATTRIBUTES << "client_class"

enqueuer = Enqueuer.new
Sidekiq.configure_server do |config|
enqueuer = Enqueuer.new(config)

config.on(:startup) do
enqueuer.start
end
Expand Down
8 changes: 6 additions & 2 deletions lib/sidekiq/staged_push/enqueuer.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# frozen_string_literal: true

require "sidekiq/component"
require "sidekiq/staged_push/enqueuer/process_batch"

module Sidekiq
module StagedPush
class Enqueuer
def initialize
include Sidekiq::Component

def initialize(config)
@done = false
@config = config
end

def start
Expand All @@ -33,7 +37,7 @@ def process
def primary_process?
return true unless defined?(Sidekiq::Enterprise)

Sidekiq::Senate.leader?
leader?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/sidekiq/staged_push/enqueuer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
it "can be started and stopped" do
allow(Sidekiq::Client).to receive_message_chain(:new, :push)

enqueuer = described_class.new
enqueuer = described_class.new("config")
enqueuer.start

job = Sidekiq::StagedPush::StagedJob.create!(payload: { args: [1] })
Expand Down

0 comments on commit b45c6e3

Please sign in to comment.