Module: ServerProcessAble
- Extended by:
- ActiveSupport::Concern
- Included in:
- Cron::Server, Delayed::Jobs::Worker
- Defined in:
- lib/app/models/concerns/server_process_able.rb
Overview
Mixin for objects that act as servers
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#check_in ⇒ Object
Perform a check in for the server.
-
#start ⇒ Object
Start the worker.
-
#stop ⇒ Object
Stop the worker.
Class Method Details
.included(base) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/app/models/concerns/server_process_able.rb', line 9 def self.included(base) base.class_eval do # # Fields # field :host_name, type: String field :pid, type: Integer field :running, type: Mongoid::Boolean, default: false field :last_check_in_at, type: Time # # Validations # validates :host_name, presence: true validates :pid, presence: true end base.extend ClassMethods end |
Instance Method Details
#check_in ⇒ Object
Perform a check in for the server
52 53 54 55 56 |
# File 'lib/app/models/concerns/server_process_able.rb', line 52 def check_in set(last_check_in_at: Time.now.utc) rescue StandardError => error App47Logger.log_error 'Unable to check in server', error end |
#start ⇒ Object
Start the worker
68 69 70 |
# File 'lib/app/models/concerns/server_process_able.rb', line 68 def start set(running: true, last_check_in_at: Time.now.utc) end |
#stop ⇒ Object
Stop the worker
61 62 63 |
# File 'lib/app/models/concerns/server_process_able.rb', line 61 def stop set(running: false, last_check_in_at: Time.now.utc) end |