Class: RubyClock

Inherits:
Object
  • Object
show all
Extended by:
Rails::ClassMethods
Includes:
AroundActions, Rails::InstanceMethods, Rake, Shell, Singleton
Defined in:
lib/ruby-clock.rb,
lib/ruby-clock/version.rb

Defined Under Namespace

Modules: AroundActions, DSL, Rails, Rake, Shell

Constant Summary collapse

VERSION =
"2.0.1"

Instance Attribute Summary collapse

Attributes included from AroundActions

#around_actions

Instance Method Summary collapse

Methods included from Rails::ClassMethods

detect_and_load_rails_app

Methods included from AroundActions

#call_with_around_action_stack, #ensure_around_trigger_has_not_been_redefined, #freeze_around_actions, #set_up_around_actions

Methods included from Shell

#shell, #shell_runner

Methods included from Rake

#prepare_rake, #rake, #rake_async, #rake_execute

Methods included from Rails::InstanceMethods

#add_rails_executor_to_around_actions

Constructor Details

#initializeRubyClock

Returns a new instance of RubyClock.



19
20
21
# File 'lib/ruby-clock.rb', line 19

def initialize
  set_up_around_actions
end

Instance Attribute Details

#around_trigger_code_locationObject

Returns the value of attribute around_trigger_code_location.



17
18
19
# File 'lib/ruby-clock.rb', line 17

def around_trigger_code_location
  @around_trigger_code_location
end

#on_errorObject

Returns the value of attribute on_error.



17
18
19
# File 'lib/ruby-clock.rb', line 17

def on_error
  @on_error
end

Instance Method Details

#listen_to_signalsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby-clock.rb', line 33

def listen_to_signals
  signals = %w[INT TERM]
  signals.each do |signal|
    old_handler = Signal.trap(signal) do
      shutdown
      if old_handler.respond_to?(:call)
        old_handler.call
      else
        exit
      end
    end
  end
  puts "RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS is set to #{wait_seconds}"
end

#run_jobsObject



52
53
54
55
56
# File 'lib/ruby-clock.rb', line 52

def run_jobs
  puts "Starting ruby-clock with #{schedule.jobs.size} jobs"
  schedule.resume
  schedule.join
end

#scheduleObject



48
49
50
# File 'lib/ruby-clock.rb', line 48

def schedule
  Rufus::Scheduler.singleton
end

#shutdownObject



27
28
29
30
31
# File 'lib/ruby-clock.rb', line 27

def shutdown
  puts "Shutting down ruby-clock. Waiting #{wait_seconds} seconds for jobs to finish..."
  schedule.shutdown(wait: wait_seconds)
  puts "...done 🐈️ 👋"
end

#wait_secondsObject



23
24
25
# File 'lib/ruby-clock.rb', line 23

def wait_seconds
  ENV['RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS']&.to_i || 29
end