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
-
#execute ⇒ Object
abstract
The code that will be executed within the run loop.
-
#start ⇒ Object
(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 ⇒ Object
Stop the run loop.
-
#stopped? ⇒ Boolean
Query if the service is currently stopped.
Instance Method Details
#execute ⇒ Object
This method is abstract.
Subclass and override #run to implement a custom Service.
The code that will be executed within the run loop.
34 35 36 |
# File 'lib/service.rb', line 34 def execute raise NotImplementedError end |
#start ⇒ Object 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.
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.
27 28 29 |
# File 'lib/service.rb', line 27 def started? @_service_state == :started end |
#stop ⇒ Object
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.
20 21 22 |
# File 'lib/service.rb', line 20 def stopped? @_service_state == :stopped end |