Module: Service::Base
- Included in:
- Service
- Defined in:
- lib/service.rb
Overview
The instance methods to be mixed into a Service.
Instance Method Summary collapse
-
#execute ⇒ Object
abstract
The code that will be executed within the run loop.
-
#execute! ⇒ Thread
Call the #execute method within a new Thread.
-
#start ⇒ Symbol
(also: #run)
Start the run loop.
-
#start! ⇒ Thread
(also: #run!)
Start the run loop in a new Thread.
-
#started? ⇒ Boolean
(also: #running?)
Query if the service is currently started.
-
#stop ⇒ Symbol
Stop the run loop.
-
#stopped? ⇒ Boolean
Query if the service is currently stopped.
Instance Method Details
#execute ⇒ Object
This method is abstract.
Override #execute to implement a custom Service.
The code that will be executed within the run loop.
28 29 30 |
# File 'lib/service.rb', line 28 def execute raise NotImplementedError end |
#execute! ⇒ Thread
Call the #execute method within a new Thread.
35 36 37 |
# File 'lib/service.rb', line 35 def execute! Thread.new { execute } end |
#start ⇒ Symbol Also known as: run
Start the run loop.
49 50 51 52 53 54 55 56 57 |
# File 'lib/service.rb', line 49 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.
64 65 66 |
# File 'lib/service.rb', line 64 def start! Thread.new { start } end |
#started? ⇒ Boolean Also known as: running?
Query if the service is currently started.
20 21 22 |
# File 'lib/service.rb', line 20 def started? @_service_state == :started end |
#stop ⇒ Symbol
Stop the run loop.
42 43 44 |
# File 'lib/service.rb', line 42 def stop @_service_state = :stopped end |
#stopped? ⇒ Boolean
Query if the service is currently stopped.
13 14 15 |
# File 'lib/service.rb', line 13 def stopped? @_service_state == :stopped end |