Module: Sidecloq::Utils

Included in:
Locker, Runner, Schedule, Scheduler
Defined in:
lib/sidecloq/utils.rb

Overview

Useful stuff

Defined Under Namespace

Modules: ClassMethods Classes: ContextLogger

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



74
75
76
# File 'lib/sidecloq/utils.rb', line 74

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#loggerObject



35
36
37
38
39
# File 'lib/sidecloq/utils.rb', line 35

def logger
  @logger ||= ContextLogger.new(
    defined?(Sidekiq::Logging) ? 'Sidecloq' : {sidecloq: true}
  )
end

#redis(&block) ⇒ Object



41
42
43
# File 'lib/sidecloq/utils.rb', line 41

def redis(&block)
  self.class.redis(&block)
end

#will_never_run(cronline) ⇒ Object

finds cron lines that are impossible, like ‘0 5 31 2 *’ note: does not attempt to fully validate the cronline



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sidecloq/utils.rb', line 47

def will_never_run(cronline)
  # look for non-existent day of month
  split = cronline.split(/\s+/)
  if split.length > 3 && split[2] =~ /\d+/ && split[3] =~ /\d+/

    month = split[3].to_i
    day = split[2].to_i
    # special case for leap-year detection
    return true if month == 2 && day <= 29

    return !Date.valid_date?(0, month, day)

  else
    false
  end
end