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

Clarify usage with global_id and sidekiq-status #455

Merged
merged 1 commit into from
Nov 26, 2019

Conversation

mhenrixon
Copy link
Owner

@mhenrixon mhenrixon commented Nov 26, 2019

Close #412

Given the following setup:

# ./myapp/config/sidekiq.rb

# frozen_string_literal: true

Sidekiq.default_worker_options = {
  backtrace: true,
  retry: false,
}

Sidekiq.client_middleware do |chain|
  chain.add Sidekiq::GlobalId::ClientMiddleware
  chain.add SidekiqUniqueJobs::Middleware::Client
end

Sidekiq.server_middleware do |chain|
  chain.add SidekiqUniqueJobs::Middleware::Server
  chain.add Sidekiq::GlobalId::ServerMiddleware
end

Sidekiq.configure_server do |config|
  config.redis = { url: ENV["REDIS_URL"], driver: :hiredis }
  config.error_handlers << ->(ex, ctx_hash) { p ex, ctx_hash }

  config.death_handlers << lambda do |job, _ex|
    digest = job["unique_digest"]
    SidekiqUniqueJobs::Digests.delete_by_digest(digest) if digest
  end

  # # accepts :expiration (optional)
  Sidekiq::Status.configure_server_middleware config, expiration: 30.minutes

  # # accepts :expiration (optional)
  Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes

  # schedule_file = "config/schedule.yml"

  # if File.exist?(schedule_file)
  #   Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
  # end
end

Sidekiq.configure_client do |config|
  config.redis = { url: ENV["REDIS_URL"], driver: :hiredis }
  # accepts :expiration (optional)
  Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes
end

Sidekiq.logger       = Sidekiq::Logger.new(STDOUT)
Sidekiq.logger.level = Logger::DEBUG
Sidekiq.log_format = :json if Sidekiq.respond_to?(:log_format)
SidekiqUniqueJobs.configure do |config|
  config.debug_lua       = true
  config.lock_info       = true
  config.max_history     = 10_000
  config.reaper          = :lua
  config.reaper_count    = 10_000
  config.reaper_interval = 10
  config.reaper_timeout  = 5
end
Dir[Rails.root.join("app", "workers", "**", "*.rb")].each { |worker| require worker }

And the following worker:

# myapp/app/workers/status_worker.rb

class StatusWorker
  include Sidekiq::Worker
  include Sidekiq::Status::Worker

  sidekiq_options lock: :until_executed

  def perform(*args)
    logger.debug("This is happening: #{args}")
  end
end

Gives me the following results

10:16:18 PM worker.1 |  2019-11-26T21:16:18.808Z pid=68864 tid=oujqx42w8 class=StatusWorker jid=67250ef5ee06bc76413a8742 elapsed=0.006 INFO: done
10:16:20 PM worker.1 |  2019-11-26T21:16:20.045Z pid=68864 tid=oujqx437w class=StatusWorker jid=cad5737a6c2f3147ad24f26a INFO: start
10:16:20 PM worker.1 |  2019-11-26T21:16:20.046Z pid=68864 tid=oujqx437w class=StatusWorker jid=cad5737a6c2f3147ad24f26a uniquejobs=server until_executed=uniquejobs:936ebc202c006847bdd226efd072781a DEBUG: This is happening: [123, 456]
10:16:20 PM worker.1 |  2019-11-26T21:16:20.049Z pid=68864 tid=oujqx437w class=StatusWorker jid=cad5737a6c2f3147ad24f26a uniquejobs=server until_executed=uniquejobs:936ebc202c006847bdd226efd072781a DEBUG: Executed unlock.lua in 0ms
10:16:20 PM worker.1 |  2019-11-26T21:16:20.049Z pid=68864 tid=oujqx437w class=StatusWorker jid=cad5737a6c2f3147ad24f26a uniquejobs=server until_executed=uniquejobs:936ebc202c006847bdd226efd072781a DEBUG: Executed unlock.lua in 1ms
10:16:20 PM worker.1 |  2019-11-26T21:16:20.050Z pid=68864 tid=oujqx437w class=StatusWorker jid=cad5737a6c2f3147ad24f26a elapsed=0.005 INFO: done```

@mhenrixon mhenrixon self-assigned this Nov 26, 2019
@mhenrixon mhenrixon merged commit 93ac186 into master Nov 26, 2019
@delete-merged-branch delete-merged-branch bot deleted the v7/clarify-usage-with-other-gems branch November 26, 2019 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jobs not pushed when using sidekiq-status
1 participant