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

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_inObject

Perform a check in for the server



52
53
54
# File 'lib/app/models/concerns/server_process_able.rb', line 52

def check_in
  set(last_check_in_at: Time.now.utc)
end

#startObject

Start the worker



66
67
68
# File 'lib/app/models/concerns/server_process_able.rb', line 66

def start
  set(running: true, last_check_in_at: Time.now.utc)
end

#stopObject

Stop the worker



59
60
61
# File 'lib/app/models/concerns/server_process_able.rb', line 59

def stop
  set(running: false, last_check_in_at: Time.now.utc)
end