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

#execute!Thread

Call the #execute method within a new Thread.

Returns:

  • (Thread)


41
42
43
# File 'lib/service.rb', line 41

def execute!
  Thread.new { execute }
end

#startObject Also known as: run

Start the run loop.



51
52
53
54
55
56
57
# File 'lib/service.rb', line 51

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)


63
64
65
# File 'lib/service.rb', line 63

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.



46
47
48
# File 'lib/service.rb', line 46

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