Module: Service::Base::InstanceMethods

Defined in:
lib/service.rb

Overview

The instance methods to be mixed into modules which include/extend Service::Base.

Instance Method Summary collapse

Instance Method Details

#executeObject

This method is abstract.

Subclass and override #run to implement a custom Service.

The code that will be executed within the run loop.

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/service.rb', line 34

def execute
  raise NotImplementedError
end

#startObject Also known as: run

Start the run loop.



44
45
46
47
48
49
50
# File 'lib/service.rb', line 44

def start
  @_service_state = :started
  loop do
    break if stopped?
    execute
  end
end

#start!Thread Also known as: run!

Start the run loop in a new Thread.

Returns:

  • (Thread)


56
57
58
# File 'lib/service.rb', line 56

def start!
  Thread.new { start }
end

#started?Boolean Also known as: running?

Query if the service is currently started.

Returns:

  • (Boolean)


27
28
29
# File 'lib/service.rb', line 27

def started?
  @_service_state == :started
end

#stopObject

Stop the run loop.



39
40
41
# File 'lib/service.rb', line 39

def stop
  @_service_state = :stopped
end

#stopped?Boolean

Query if the service is currently stopped.

Returns:

  • (Boolean)


20
21
22
# File 'lib/service.rb', line 20

def stopped?
  @_service_state == :stopped
end