Class: SpiderGazelle::Signaller

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSignaller

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

#gazelleObject

Returns the value of attribute gazelle.



12
13
14
# File 'lib/spider-gazelle/signaller.rb', line 12

def gazelle
  @gazelle
end

#is_connectedObject (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

#pipeObject (readonly)

Returns the value of attribute pipe.



11
12
13
# File 'lib/spider-gazelle/signaller.rb', line 11

def pipe
  @pipe
end

#shutting_downObject (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

#threadObject (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

#checkObject



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_failureObject



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(options)
    defer = @thread.defer

    defer.resolve(true)

    defer.promise
end

#shutdownObject



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