Skip to content

Commit

Permalink
Merge pull request #3 from Paradem/restore_formatting
Browse files Browse the repository at this point in the history
Put the formatting back so that it matches the rest of the codebase
  • Loading branch information
netikular authored Nov 7, 2023
2 parents efe5704 + e1270b1 commit 5c6e4d2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 65 deletions.
74 changes: 37 additions & 37 deletions lib/good_job/cli.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "thor"
require 'thor'

module GoodJob
#
Expand Down Expand Up @@ -55,46 +55,46 @@ def exit_on_failure?
DESCRIPTION
method_option :queues,
type: :string,
banner: "QUEUE_LIST",
desc: "Queues or queue pools to work from. (env var: GOOD_JOB_QUEUES, default: *)"
type: :string,
banner: "QUEUE_LIST",
desc: "Queues or queue pools to work from. (env var: GOOD_JOB_QUEUES, default: *)"
method_option :max_threads,
type: :numeric,
banner: "COUNT",
desc: "Default number of threads per pool to use for working jobs. (env var: GOOD_JOB_MAX_THREADS, default: 5)"
type: :numeric,
banner: 'COUNT',
desc: "Default number of threads per pool to use for working jobs. (env var: GOOD_JOB_MAX_THREADS, default: 5)"
method_option :poll_interval,
type: :numeric,
banner: "SECONDS",
desc: "Interval between polls for available jobs in seconds (env var: GOOD_JOB_POLL_INTERVAL, default: 5)"
type: :numeric,
banner: 'SECONDS',
desc: "Interval between polls for available jobs in seconds (env var: GOOD_JOB_POLL_INTERVAL, default: 5)"
method_option :max_cache,
type: :numeric,
banner: "COUNT",
desc: "Maximum number of scheduled jobs to cache in memory (env var: GOOD_JOB_MAX_CACHE, default: 10000)"
type: :numeric,
banner: 'COUNT',
desc: "Maximum number of scheduled jobs to cache in memory (env var: GOOD_JOB_MAX_CACHE, default: 10000)"
method_option :shutdown_timeout,
type: :numeric,
banner: "SECONDS",
desc: "Number of seconds to wait for jobs to finish when shutting down before stopping the thread. (env var: GOOD_JOB_SHUTDOWN_TIMEOUT, default: -1 (forever))"
type: :numeric,
banner: 'SECONDS',
desc: "Number of seconds to wait for jobs to finish when shutting down before stopping the thread. (env var: GOOD_JOB_SHUTDOWN_TIMEOUT, default: -1 (forever))"
method_option :enable_cron,
type: :boolean,
desc: "Whether to run cron process (default: false)"
type: :boolean,
desc: "Whether to run cron process (default: false)"
method_option :daemonize,
type: :boolean,
desc: "Run as a background daemon (default: false)"
type: :boolean,
desc: "Run as a background daemon (default: false)"
method_option :pidfile,
type: :string,
desc: "Path to write daemonized Process ID (env var: GOOD_JOB_PIDFILE, default: tmp/pids/good_job.pid)"
type: :string,
desc: "Path to write daemonized Process ID (env var: GOOD_JOB_PIDFILE, default: tmp/pids/good_job.pid)"
method_option :probe_port,
type: :numeric,
banner: "PORT",
desc: "Port for http health check (env var: GOOD_JOB_PROBE_PORT, default: nil)"
type: :numeric,
banner: 'PORT',
desc: "Port for http health check (env var: GOOD_JOB_PROBE_PORT, default: nil)"
method_option :queue_select_limit,
type: :numeric,
banner: "COUNT",
desc: "The number of queued jobs to select when polling for a job to run. (env var: GOOD_JOB_QUEUE_SELECT_LIMIT, default: nil)"
type: :numeric,
banner: 'COUNT',
desc: "The number of queued jobs to select when polling for a job to run. (env var: GOOD_JOB_QUEUE_SELECT_LIMIT, default: nil)"
method_option :count_till_idle,
type: :numeric,
banner: "COUNT_TILL_IDLE",
desc: "Approximatly how long in seconds to wait before good_job exits"
type: :numeric,
banner: 'COUNT_TILL_IDLE',
desc: 'Approximatly how long in seconds to wait before good_job exits'

def start
set_up_application!
Expand All @@ -113,7 +113,7 @@ def start
probe_server.start
end

require "concurrent/atomic/event"
require 'concurrent/atomic/event'
@stop_good_job_executable = Concurrent::Event.new
%w[INT TERM].each do |signal|
trap(signal) { Thread.new { @stop_good_job_executable.set }.join }
Expand All @@ -122,9 +122,9 @@ def start
@checks = configuration.count_till_idle
Kernel.loop do
sleep 0.1
if configuration.count_till_idle.positive? && capsule.stats[:active_threads] == 0
if configuration.count_till_idle.positive? && capsule.stats[:active_threads].positive?
@checks -= 1
elsif capsule.stats[:active_threads] > 0
elsif capsule.stats[:active_threads].positive?
@checks = configuration.count_till_idle
end

Expand All @@ -149,9 +149,9 @@ def start
DESCRIPTION
method_option :before_seconds_ago,
type: :numeric,
banner: "SECONDS",
desc: "Destroy records finished more than this many seconds ago (env var: GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO, default: 1209600 (14 days))"
type: :numeric,
banner: 'SECONDS',
desc: "Destroy records finished more than this many seconds ago (env var: GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO, default: 1209600 (14 days))"

def cleanup_preserved_jobs
set_up_application!
Expand Down
56 changes: 28 additions & 28 deletions lib/good_job/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Configuration
DEFAULT_DASHBOARD_DEFAULT_LOCALE = :en

def self.validate_execution_mode(execution_mode)
raise ArgumentError, "GoodJob execution mode must be one of #{EXECUTION_MODES.join(", ")}. It was '#{execution_mode}' which is not valid." unless execution_mode.in?(EXECUTION_MODES)
raise ArgumentError, "GoodJob execution mode must be one of #{EXECUTION_MODES.join(', ')}. It was '#{execution_mode}' which is not valid." unless execution_mode.in?(EXECUTION_MODES)
end

# The options that were explicitly set when initializing +Configuration+.
Expand Down Expand Up @@ -92,8 +92,8 @@ def validate!
# @return [Symbol]
def execution_mode
mode = options[:execution_mode] ||
rails_config[:execution_mode] ||
env["GOOD_JOB_EXECUTION_MODE"]
rails_config[:execution_mode] ||
env['GOOD_JOB_EXECUTION_MODE']
mode = mode.to_sym if mode

if mode
Expand Down Expand Up @@ -121,8 +121,8 @@ def max_threads
(
options[:max_threads] ||
rails_config[:max_threads] ||
env["GOOD_JOB_MAX_THREADS"] ||
env["RAILS_MAX_THREADS"] ||
env['GOOD_JOB_MAX_THREADS'] ||
env['RAILS_MAX_THREADS'] ||
DEFAULT_MAX_THREADS
).to_i
end
Expand All @@ -135,8 +135,8 @@ def max_threads
def queue_string
options[:queues].presence ||
rails_config[:queues].presence ||
env["GOOD_JOB_QUEUES"].presence ||
"*"
env['GOOD_JOB_QUEUES'].presence ||
'*'
end

# The number of seconds between polls for jobs. GoodJob will execute jobs
Expand All @@ -147,7 +147,7 @@ def poll_interval
interval = (
options[:poll_interval] ||
rails_config[:poll_interval] ||
env["GOOD_JOB_POLL_INTERVAL"]
env['GOOD_JOB_POLL_INTERVAL']
)

if interval
Expand All @@ -171,7 +171,7 @@ def max_cache
(
options[:max_cache] ||
rails_config[:max_cache] ||
env["GOOD_JOB_MAX_CACHE"] ||
env['GOOD_JOB_MAX_CACHE'] ||
DEFAULT_MAX_CACHE
).to_i
end
Expand All @@ -183,7 +183,7 @@ def shutdown_timeout
(
options[:shutdown_timeout] ||
rails_config[:shutdown_timeout] ||
env["GOOD_JOB_SHUTDOWN_TIMEOUT"] ||
env['GOOD_JOB_SHUTDOWN_TIMEOUT'] ||
DEFAULT_SHUTDOWN_TIMEOUT
).to_f
end
Expand All @@ -194,16 +194,16 @@ def enable_cron
value = ActiveModel::Type::Boolean.new.cast(
options[:enable_cron] ||
rails_config[:enable_cron] ||
env["GOOD_JOB_ENABLE_CRON"] ||
env['GOOD_JOB_ENABLE_CRON'] ||
false
)
value && cron.size.positive?
end

alias_method :enable_cron?, :enable_cron
alias enable_cron? enable_cron

def cron
env_cron = JSON.parse(ENV.fetch("GOOD_JOB_CRON"), symbolize_names: true) if ENV["GOOD_JOB_CRON"].present?
env_cron = JSON.parse(ENV.fetch('GOOD_JOB_CRON'), symbolize_names: true) if ENV['GOOD_JOB_CRON'].present?

options[:cron] ||
rails_config[:cron] ||
Expand All @@ -224,7 +224,7 @@ def queue_select_limit
(
options[:queue_select_limit] ||
rails_config[:queue_select_limit] ||
env["GOOD_JOB_QUEUE_SELECT_LIMIT"]
env['GOOD_JOB_QUEUE_SELECT_LIMIT']
)&.to_i
end

Expand All @@ -236,15 +236,15 @@ def count_till_idle
(
options[:count_till_idle] ||
rails_config[:count_till_idle] ||
env["GOOD_JOB_COUNT_TILL_IDLE"]
env['GOOD_JOB_COUNT_TILL_IDLE']
)&.to_i&.*(10) || -1
end

# Whether to automatically destroy discarded jobs that have been preserved.
# @return [Boolean]
def cleanup_discarded_jobs?
return rails_config[:cleanup_discarded_jobs] unless rails_config[:cleanup_discarded_jobs].nil?
return ActiveModel::Type::Boolean.new.cast(env["GOOD_JOB_CLEANUP_DISCARDED_JOBS"]) unless env["GOOD_JOB_CLEANUP_DISCARDED_JOBS"].nil?
return ActiveModel::Type::Boolean.new.cast(env['GOOD_JOB_CLEANUP_DISCARDED_JOBS']) unless env['GOOD_JOB_CLEANUP_DISCARDED_JOBS'].nil?

true
end
Expand All @@ -255,7 +255,7 @@ def cleanup_preserved_jobs_before_seconds_ago
(
options[:before_seconds_ago] ||
rails_config[:cleanup_preserved_jobs_before_seconds_ago] ||
env["GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO"] ||
env['GOOD_JOB_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO'] ||
DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO
).to_i
end
Expand All @@ -277,14 +277,14 @@ def cleanup_interval_jobs
)
value = -1
end
elsif env.key?("GOOD_JOB_CLEANUP_INTERVAL_JOBS")
value = env["GOOD_JOB_CLEANUP_INTERVAL_JOBS"]
elsif env.key?('GOOD_JOB_CLEANUP_INTERVAL_JOBS')
value = env['GOOD_JOB_CLEANUP_INTERVAL_JOBS']
if value.blank?
GoodJob.deprecator.warn(
%(Setting `GOOD_JOB_CLEANUP_INTERVAL_JOBS` to `""` will no longer disable count-based cleanups in GoodJob v4. Set to `0` to disable, or `-1` to run every time.)
)
value = false
elsif value == "0"
elsif value == '0'
value = false
end
else
Expand Down Expand Up @@ -312,14 +312,14 @@ def cleanup_interval_seconds
)
value = -1
end
elsif env.key?("GOOD_JOB_CLEANUP_INTERVAL_SECONDS")
value = env["GOOD_JOB_CLEANUP_INTERVAL_SECONDS"]
elsif env.key?('GOOD_JOB_CLEANUP_INTERVAL_SECONDS')
value = env['GOOD_JOB_CLEANUP_INTERVAL_SECONDS']
if value.blank?
GoodJob.deprecator.warn(
%(Setting `GOOD_JOB_CLEANUP_INTERVAL_SECONDS` to `""` will no longer disable time-based cleanups in GoodJob v4. Set to `0` to disable, or `-1` to run every time.)
)
value = false
elsif value == "0"
elsif value == '0'
value = false
end
else
Expand All @@ -339,21 +339,21 @@ def daemonize?
# @return [Pathname,String]
def pidfile
options[:pidfile] ||
env["GOOD_JOB_PIDFILE"] ||
Rails.application.root.join("tmp", "pids", "good_job.pid")
env['GOOD_JOB_PIDFILE'] ||
Rails.application.root.join('tmp', 'pids', 'good_job.pid')
end

# Port of the probe server
# @return [nil,Integer]
def probe_port
options[:probe_port] ||
env["GOOD_JOB_PROBE_PORT"]
env['GOOD_JOB_PROBE_PORT']
end

def enable_listen_notify
return options[:enable_listen_notify] unless options[:enable_listen_notify].nil?
return rails_config[:enable_listen_notify] unless rails_config[:enable_listen_notify].nil?
return ActiveModel::Type::Boolean.new.cast(env["GOOD_JOB_ENABLE_LISTEN_NOTIFY"]) unless env["GOOD_JOB_ENABLE_LISTEN_NOTIFY"].nil?
return ActiveModel::Type::Boolean.new.cast(env['GOOD_JOB_ENABLE_LISTEN_NOTIFY']) unless env['GOOD_JOB_ENABLE_LISTEN_NOTIFY'].nil?

DEFAULT_ENABLE_LISTEN_NOTIFY
end
Expand All @@ -375,7 +375,7 @@ def in_webserver?
self_caller = caller
self_caller.grep(%r{config.ru}).any? || # EXAMPLE: config.ru:3:in `block in <main>' OR config.ru:3:in `new_from_string'
self_caller.grep(%r{puma/request}).any? || # EXAMPLE: puma-5.6.4/lib/puma/request.rb:76:in `handle_request'
self_caller.grep(%(/rack/handler/)).any? || # EXAMPLE: iodine-0.7.44/lib/rack/handler/iodine.rb:13:in `start'
self_caller.grep(%{/rack/handler/}).any? || # EXAMPLE: iodine-0.7.44/lib/rack/handler/iodine.rb:13:in `start'
(Concurrent.on_jruby? && self_caller.grep(%r{jruby/rack/rails_booter}).any?) # EXAMPLE: uri:classloader:/jruby/rack/rails_booter.rb:83:in `load_environment'
end || false
end
Expand Down

0 comments on commit 5c6e4d2

Please sign in to comment.