Module: Procrastinator::Scheduler::DaemonWorking
Overview
Daemonized work style
Defined Under Namespace
Classes: ProcessExistsError
Constant Summary collapse
- PID_EXT =
File extension for process ID files
'.pid'- DEFAULT_PID_DIR =
Default directory to store PID files in.
Pathname.new('/tmp').freeze
Constants included from ThreadedWorking
Class Method Summary collapse
-
.halt!(pid_path) ⇒ Object
Stops the procrastinator process denoted by the provided pid file.
-
.normalize_pid(pid_path) ⇒ Object
Normalizes the given pid path, including conversion to absolute path and defaults.
- .running?(pid_path) ⇒ Boolean
Instance Method Summary collapse
-
#daemonized!(pid_path = nil) ⇒ Object
Consumes the current process and turns it into a background daemon and proceed as #threaded.
Methods included from ThreadedWorking
Class Method Details
.halt!(pid_path) ⇒ Object
Stops the procrastinator process denoted by the provided pid file
287 288 289 290 291 |
# File 'lib/procrastinator/scheduler.rb', line 287 def self.halt!(pid_path) pid_path = normalize_pid pid_path Process.kill('TERM', pid_path.read.to_i) end |
.normalize_pid(pid_path) ⇒ Object
Normalizes the given pid path, including conversion to absolute path and defaults.
279 280 281 282 283 284 |
# File 'lib/procrastinator/scheduler.rb', line 279 def self.normalize_pid(pid_path) normalized = Pathname.new(pid_path || DEFAULT_PID_DIR) normalized /= "#{ PROG_NAME.downcase }#{ PID_EXT }" unless normalized.extname == PID_EXT normalized. end |
.running?(pid_path) ⇒ Boolean
293 294 295 296 297 298 299 300 301 302 |
# File 'lib/procrastinator/scheduler.rb', line 293 def self.running?(pid_path) pid = normalize_pid(pid_path).read.to_i # this raises Errno::ESRCH when no process found, therefore if found we should exit Process.getpgid pid true rescue Errno::ENOENT, Errno::ESRCH false end |
Instance Method Details
#daemonized!(pid_path = nil) ⇒ Object
Consumes the current process and turns it into a background daemon and proceed as #threaded. Additional logging is recorded in the directory specified by the Procrastinator.setup configuration.
If pid_path ends with extension ‘.pid’, the basename will be requested as process title (depending on OS support). An extensionless path is assumed to be a directory and a default filename (and proctitle) is used.
270 271 272 273 274 |
# File 'lib/procrastinator/scheduler.rb', line 270 def daemonized!(pid_path = nil) spawn_daemon(pid_path) threaded end |