Module: Scheduler
- Defined in:
- lib/scheduler.rb,
lib/scheduler/cli.rb,
lib/scheduler/version.rb,
lib/scheduler/schedulable.rb,
lib/scheduler/main_process.rb,
lib/scheduler/configuration.rb,
lib/scheduler/examples/executable_class.rb,
lib/scheduler/examples/schedulable_model.rb
Defined Under Namespace
Modules: Examples, Schedulable Classes: CLI, Configuration, Error, MainProcess
Constant Summary collapse
- VERSION =
"1.0.5"
Class Attribute Summary collapse
-
.configuration ⇒ Scheduler::Configuration
Initializes configuration.
Class Method Summary collapse
-
.configure {|@configuration| ... } ⇒ nil
Method to configure various Scheduler options.
-
.env ⇒ String
Returns current environment.
-
.logger ⇒ Logger
Return the Scheduler logger.
-
.perform_jobs_in_test_or_development? ⇒ Boolean
Checks whether to run jobs in test or development.
-
.pid ⇒ Integer
Gets scheduler main process pid.
-
.pid_file ⇒ String
Gets scheduler pid file.
-
.restart ⇒ nil
Restarts the scheduler.
-
.root ⇒ String
Returns Scheduler gem root path.
-
.start ⇒ nil
Starts a Scheduler::MainProcess in a separate process.
-
.stop ⇒ nil
Reschedules all running jobs and stops the scheduler main process.
Class Attribute Details
.configuration ⇒ Scheduler::Configuration
Initializes configuration.
18 19 20 |
# File 'lib/scheduler.rb', line 18 def configuration @configuration end |
Class Method Details
.configure {|@configuration| ... } ⇒ nil
Method to configure various Scheduler options.
32 33 34 35 |
# File 'lib/scheduler.rb', line 32 def configure @configuration ||= Scheduler::Configuration.new yield @configuration end |
.env ⇒ String
Returns current environment.
49 50 51 |
# File 'lib/scheduler.rb', line 49 def env Scheduler.configuration.environment end |
.logger ⇒ Logger
Return the Scheduler logger.
81 82 83 |
# File 'lib/scheduler.rb', line 81 def logger @@logger ||= Logger.new Scheduler.configuration.log_file end |
.perform_jobs_in_test_or_development? ⇒ Boolean
Checks whether to run jobs in test or development.
73 74 75 |
# File 'lib/scheduler.rb', line 73 def perform_jobs_in_test_or_development? Scheduler.configuration.perform_jobs_in_test_or_development end |
.pid ⇒ Integer
Gets scheduler main process pid.
65 66 67 |
# File 'lib/scheduler.rb', line 65 def pid File.read(self.pid_file).to_i rescue nil end |
.pid_file ⇒ String
Gets scheduler pid file.
57 58 59 |
# File 'lib/scheduler.rb', line 57 def pid_file '/tmp/scheduler.pid' end |
.restart ⇒ nil
Restarts the scheduler.
124 125 126 127 |
# File 'lib/scheduler.rb', line 124 def restart self.stop self.start end |
.root ⇒ String
Returns Scheduler gem root path.
41 42 43 |
# File 'lib/scheduler.rb', line 41 def root File.dirname __dir__ end |
.start ⇒ nil
Starts a Scheduler::MainProcess in a separate process.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/scheduler.rb', line 89 def start logger.info Rainbow("[Scheduler:#{Process.pid}] Starting..").cyan scheduler_pid = Process.fork do begin logger.info Rainbow("[Scheduler:#{Process.pid}] Forked.").cyan Process.daemon true, true logger.info Rainbow("[Scheduler:#{Process.pid}] Going into background..").cyan File.open(self.pid_file, 'w+') do |pidfile| pidfile.puts Process.pid end scheduler = Scheduler::MainProcess.new rescue StandardError => error puts Rainbow("#{error.class}: #{error.} (#{error.backtrace.first})").red end end Process.detach(scheduler_pid) scheduler_pid end |