Class: RubyClock
- Inherits:
-
Object
- Object
- RubyClock
- 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
-
#around_trigger_code_location ⇒ Object
Returns the value of attribute around_trigger_code_location.
-
#on_error ⇒ Object
Returns the value of attribute on_error.
Attributes included from AroundActions
Instance Method Summary collapse
-
#initialize ⇒ RubyClock
constructor
A new instance of RubyClock.
- #listen_to_signals ⇒ Object
- #run_jobs ⇒ Object
- #schedule ⇒ Object
- #shutdown ⇒ Object
- #wait_seconds ⇒ Object
Methods included from Rails::ClassMethods
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
Methods included from Rake
#prepare_rake, #rake, #rake_async, #rake_execute
Methods included from Rails::InstanceMethods
#add_rails_executor_to_around_actions
Constructor Details
#initialize ⇒ RubyClock
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_location ⇒ Object
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_error ⇒ Object
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_signals ⇒ Object
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_jobs ⇒ Object
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 |
#schedule ⇒ Object
48 49 50 |
# File 'lib/ruby-clock.rb', line 48 def schedule Rufus::Scheduler.singleton end |
#shutdown ⇒ Object
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_seconds ⇒ Object
23 24 25 |
# File 'lib/ruby-clock.rb', line 23 def wait_seconds ENV['RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS']&.to_i || 29 end |