Class: SpiderGazelle::LaunchControl
- Inherits:
-
Object
- Object
- SpiderGazelle::LaunchControl
- Includes:
- Singleton
- Defined in:
- lib/spider-gazelle.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
Instance Method Summary collapse
- #exec(args) ⇒ Object
- #launch(options) ⇒ Object
-
#launch_spider(args) ⇒ Object
————————————— SPIDER LAUNCH CONTROL —————————————.
- #shutdown ⇒ Object
-
#signal_master(reactor, signaller, logger, options) ⇒ Object
————————————— TTY SIGNALLING CONTROL —————————————.
-
#start_spider(signaller, logger, options) ⇒ Object
This is called when a spider process starts.
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
31 32 33 |
# File 'lib/spider-gazelle.rb', line 31 def args @args end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
31 32 33 |
# File 'lib/spider-gazelle.rb', line 31 def password @password end |
Instance Method Details
#exec(args) ⇒ Object
34 35 36 37 38 |
# File 'lib/spider-gazelle.rb', line 34 def exec(args) = SpiderGazelle::Options.sanitize(args) @args = args launch() end |
#launch(options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/spider-gazelle.rb', line 40 def launch() # Enable verbose messages if requested Logger.instance.verbose! if [0][:verbose] # Start the Libuv Event Loop reactor = ::SpiderGazelle::Reactor.instance reactor.run do # Check if SG is already running signaller = ::SpiderGazelle::Signaller.instance if [0][:isolate] # This ensures this process will load the spider code [0][:spider] = true boot(true, signaller, ) else signaller.check.then do |running| boot(running, signaller, ) end end end end |
#launch_spider(args) ⇒ Object
SPIDER LAUNCH CONTROL
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/spider-gazelle.rb', line 74 def launch_spider(args) require 'securerandom' @password ||= SecureRandom.hex #cmd = "#{EXEC_NAME} -s #{@password} #{Shellwords.join(args)}" thread = Reactor.instance.thread spider = thread.spawn(EXEC_NAME, args: (['-s', @password] + args), mode: :inherit) spider.finally do signaller = ::SpiderGazelle::Signaller.instance signaller.panic!('Unexpected spider exit') unless signaller.shutting_down end end |
#shutdown ⇒ Object
63 64 65 66 67 68 |
# File 'lib/spider-gazelle.rb', line 63 def shutdown reactor = Reactor.instance reactor.thread.schedule do reactor.shutdown end end |
#signal_master(reactor, signaller, logger, options) ⇒ Object
TTY SIGNALLING CONTROL
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/spider-gazelle.rb', line 99 def signal_master(reactor, signaller, logger, ) # This is a signal request promise = signaller.request() promise.then do |result| logger.info "signal recieved #{result}" end promise.catch do |error| logger.info "there was an error #{error}" end promise.finally do reactor.shutdown end end |
#start_spider(signaller, logger, options) ⇒ Object
This is called when a spider process starts
90 91 92 93 |
# File 'lib/spider-gazelle.rb', line 90 def start_spider(signaller, logger, ) require 'spider-gazelle/spider' Spider.instance.run!() end |