Skip to content

Commit

Permalink
formatting, ensure environment is updated in Sidekiq.options
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed May 25, 2023
1 parent ad0f13c commit fa6723e
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 25 deletions.
13 changes: 7 additions & 6 deletions lib/sidekiq/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
require "sidekiq/launcher"

# module ScoutApm
# VERSION = "5.3.1"
# VERSION = "5.3.1"
# end
fail <<~EOM if defined?(ScoutApm::VERSION) && ScoutApm::VERSION < "5.2.0"
scout_apm v#{ScoutApm::VERSION} is unsafe with Sidekiq 6.5. Please run `bundle up scout_apm` to upgrade to 5.2.0 or greater.
scout_apm v#{ScoutApm::VERSION} is unsafe with Sidekiq 6.5. Please run `bundle up scout_apm` to upgrade to 5.2.0 or greater.
EOM

module Sidekiq # :nodoc:
Expand Down Expand Up @@ -225,6 +225,7 @@ def set_environment(cli_env)
# Both Sinatra 2.0+ and Sidekiq support this term.
# RAILS_ENV and RACK_ENV are there for legacy support.
@environment = cli_env || ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
config[:environment] = @environment
end

def symbolize_keys_deep!(hash)
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def enqueue_to(queue, klass, *args)
def enqueue_to_in(queue, interval, klass, *args)
int = interval.to_f
now = Time.now.to_f
ts = (int < 1_000_000_000 ? now + int : int)
ts = ((int < 1_000_000_000) ? now + int : int)

item = {"class" => klass, "args" => args, "at" => ts, "queue" => queue}
item.delete("at") if ts <= now
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq/metrics/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def total_avg(metric = "ms")
def series_avg(metric = "ms")
series[metric].each_with_object(Hash.new(0)) do |(bucket, value), result|
completed = series.dig("p", bucket) - series.dig("f", bucket)
result[bucket] = completed == 0 ? 0 : value.to_f / completed
result[bucket] = (completed == 0) ? 0 : value.to_f / completed
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def tags_for(process)
tags = [
process["tag"],
process["labels"],
(process["quiet"] == "true" ? "quiet" : nil)
((process["quiet"] == "true") ? "quiet" : nil)
].flatten.compact
tags.any? ? "[#{tags.join("] [")}]" : nil
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sidekiq/paginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Sidekiq
module Paginator
def page(key, pageidx = 1, page_size = 25, opts = nil)
current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i
current_page = (pageidx.to_i < 1) ? 1 : pageidx.to_i
pageidx = current_page - 1
total_size = 0
items = []
Expand Down Expand Up @@ -45,7 +45,7 @@ def page(key, pageidx = 1, page_size = 25, opts = nil)
end

def page_items(items, pageidx = 1, page_size = 25)
current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i
current_page = (pageidx.to_i < 1) ? 1 : pageidx.to_i
pageidx = current_page - 1
starting = pageidx * page_size
items = items.to_a
Expand Down
6 changes: 3 additions & 3 deletions lib/sidekiq/web/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def t(msg, options = {})
end

def sort_direction_label
params[:direction] == "asc" ? "&uarr;" : "&darr;"
(params[:direction] == "asc") ? "&uarr;" : "&darr;"
end

def workset
Expand Down Expand Up @@ -188,7 +188,7 @@ def current_path
end

def current_status
workset.size == 0 ? "idle" : "active"
(workset.size == 0) ? "idle" : "active"
end

def relative_time(time)
Expand Down Expand Up @@ -221,7 +221,7 @@ def to_query_string(params)
end

def truncate(text, truncate_after_chars = 2000)
truncate_after_chars && text.size > truncate_after_chars ? "#{text[0..truncate_after_chars]}..." : text
(truncate_after_chars && text.size > truncate_after_chars) ? "#{text[0..truncate_after_chars]}..." : text
end

def display_args(args, truncate_after_chars = 2000)
Expand Down
4 changes: 2 additions & 2 deletions lib/sidekiq/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def perform_in(interval, *args)
def at(interval)
int = interval.to_f
now = Time.now.to_f
ts = (int < 1_000_000_000 ? now + int : int)
ts = ((int < 1_000_000_000) ? now + int : int)
# Optimization to enqueue something now that is scheduled to go out now or in the past
@opts["at"] = ts if ts > now
self
Expand Down Expand Up @@ -324,7 +324,7 @@ def perform_bulk(*args, **kwargs)
def perform_in(interval, *args)
int = interval.to_f
now = Time.now.to_f
ts = (int < 1_000_000_000 ? now + int : int)
ts = ((int < 1_000_000_000) ? now + int : int)

item = {"class" => self, "args" => args}

Expand Down
7 changes: 4 additions & 3 deletions test/test_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
describe Sidekiq::CLI do
describe "#parse" do
before do
ENV["RAILS_ENV"] = ENV["RACK_ENV"] = nil
Sidekiq.reset!
@logger = Sidekiq.logger
@logdev = StringIO.new
Expand Down Expand Up @@ -168,12 +169,12 @@ def logdev

describe "config file" do
it "accepts with -C" do
subject.parse(%w[sidekiq -C ./test/config.yml])
subject.parse(%w[sidekiq -C ./test/config.yml -e production])

assert_equal "./test/config.yml", config[:config_file]
refute config[:verbose]
assert_equal "./test/fake_env.rb", config[:require]
assert_nil config[:environment]
assert_equal "production", config[:environment]
assert_equal 50, config[:concurrency]
assert_equal 2, config[:queues].count { |q| q == "very_often" }
assert_equal 1, config[:queues].count { |q| q == "seldom" }
Expand All @@ -185,7 +186,7 @@ def logdev
assert_equal "./test/config_string.yml", config[:config_file]
refute config[:verbose]
assert_equal "./test/fake_env.rb", config[:require]
assert_nil config[:environment]
assert_equal "development", config[:environment]
assert_equal 50, config[:concurrency]
assert_equal 2, config[:queues].count { |q| q == "very_often" }
assert_equal 1, config[:queues].count { |q| q == "seldom" }
Expand Down
2 changes: 1 addition & 1 deletion test/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
it "allows middleware to stop bulk jobs" do
mware = Class.new do
def call(worker_klass, msg, q, r)
msg["args"][0] == 1 ? yield : false
(msg["args"][0] == 1) ? yield : false
end
end
client = Sidekiq::Client.new
Expand Down
2 changes: 0 additions & 2 deletions test/test_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ def call(worker, item, queue, redis_pool)
class CustomJobLogger < Sidekiq::JobLogger
def call(item, queue)
yield
rescue Exception
raise
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def job
max_retries = 7
1.upto(max_retries + 1) do |i|
assert_raises RuntimeError do
job = i > 1 ? jobstr("retry_count" => i - 2) : jobstr
job = (i > 1) ? jobstr("retry_count" => i - 2) : jobstr
@config[:max_retries] = max_retries
handler.local(worker, job, "default") do
raise "kerblammo!"
Expand Down
3 changes: 1 addition & 2 deletions test/test_web_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def env
end

def default
{
}
{}
end
end

Expand Down

0 comments on commit fa6723e

Please sign in to comment.