Class: SpiderGazelle::Signaller
- Inherits:
-
Object
- Object
- SpiderGazelle::Signaller
- Includes:
- Singleton
- Defined in:
- lib/spider-gazelle/signaller.rb,
lib/spider-gazelle/signaller/signal_parser.rb
Defined Under Namespace
Classes: SignalParser
Instance Attribute Summary collapse
-
#gazelle ⇒ Object
Returns the value of attribute gazelle.
-
#is_connected ⇒ Object
readonly
Returns the value of attribute is_connected.
-
#pipe ⇒ Object
readonly
Returns the value of attribute pipe.
-
#shutting_down ⇒ Object
readonly
Returns the value of attribute shutting_down.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
Instance Method Summary collapse
-
#authenticate(password) ⇒ Object
—————————— Called from the spider process ——————————.
- #check ⇒ Object
- #general_failure ⇒ Object
-
#initialize ⇒ Signaller
constructor
A new instance of Signaller.
- #request(options) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize ⇒ Signaller
Returns a new instance of Signaller.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/spider-gazelle/signaller.rb', line 15 def initialize @thread = ::Libuv::Reactor.default @logger = Logger.instance # This is used to check if an instance of spider-gazelle is already running @is_master = false @is_client = false @is_connected = false @shutting_down = false @client_check = @thread.defer @validated = [] # Set requires more processing @validating = {} end |
Instance Attribute Details
#gazelle ⇒ Object
Returns the value of attribute gazelle.
12 13 14 |
# File 'lib/spider-gazelle/signaller.rb', line 12 def gazelle @gazelle end |
#is_connected ⇒ Object (readonly)
Returns the value of attribute is_connected.
11 12 13 |
# File 'lib/spider-gazelle/signaller.rb', line 11 def is_connected @is_connected end |
#pipe ⇒ Object (readonly)
Returns the value of attribute pipe.
11 12 13 |
# File 'lib/spider-gazelle/signaller.rb', line 11 def pipe @pipe end |
#shutting_down ⇒ Object (readonly)
Returns the value of attribute shutting_down.
11 12 13 |
# File 'lib/spider-gazelle/signaller.rb', line 11 def shutting_down @shutting_down end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
11 12 13 |
# File 'lib/spider-gazelle/signaller.rb', line 11 def thread @thread end |
Class Method Details
.general_failure(_) ⇒ Object
82 83 84 |
# File 'lib/spider-gazelle/signaller.rb', line 82 def self.general_failure(_) Reactor.instance.shutdown end |
Instance Method Details
#authenticate(password) ⇒ Object
Called from the spider process
71 72 73 |
# File 'lib/spider-gazelle/signaller.rb', line 71 def authenticate(password) @pipe.write "\x02validate #{password}\x03" end |
#check ⇒ Object
37 38 39 40 41 42 |
# File 'lib/spider-gazelle/signaller.rb', line 37 def check @thread.next_tick do connect_to_sg_master end @client_check.promise end |
#general_failure ⇒ Object
75 76 77 78 79 80 |
# File 'lib/spider-gazelle/signaller.rb', line 75 def general_failure @pipe.write "\x02Signaller general_failure\x03" rescue ensure Reactor.instance.shutdown end |
#request(options) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/spider-gazelle/signaller.rb', line 29 def request() defer = @thread.defer defer.resolve(true) defer.promise end |
#shutdown ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/spider-gazelle/signaller.rb', line 44 def shutdown defer = @thread.defer @shutting_down = true # Close the SIGNAL_SERVER pipe @pipe.close if @is_connected # Request spider or gazelle process to shutdown if @gazelle @gazelle.shutdown(defer) end if defined?(::SpiderGazelle::Spider) Spider.instance.shutdown(defer) else # This must be the master process @thread.next_tick do defer.resolve(true) end end defer.promise end |