Class: OpalWebpackLoader::CompileWorker
- Inherits:
-
Object
- Object
- OpalWebpackLoader::CompileWorker
- Defined in:
- lib/opal-webpack-loader/compile_worker.rb
Constant Summary collapse
- SIGNALS =
%w[QUIT]
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#compiler_options_digest ⇒ Object
readonly
Returns the value of attribute compiler_options_digest.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#tempfile ⇒ Object
readonly
Returns the value of attribute tempfile.
Instance Method Summary collapse
- #==(other_number) ⇒ Object
-
#initialize(master_pid, socket, tempfile, number, compiler_options, other_options) ⇒ CompileWorker
constructor
A new instance of CompileWorker.
- #start ⇒ Object
Constructor Details
#initialize(master_pid, socket, tempfile, number, compiler_options, other_options) ⇒ CompileWorker
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/opal-webpack-loader/compile_worker.rb', line 9 def initialize(master_pid, socket, tempfile, number, , ) @master_pid = master_pid @socket = socket @tempfile = tempfile @number = number = .merge(es6_modules: true) if [:memcached] @cache = Dalli::Client.new([:memchached]) elsif [:redis] @cache = Redis.new(url: [:redis]) else @cache = false end = Digest::SHA1.hexdigest(Oj.dump(, mode: :strict)) if cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
7 8 9 |
# File 'lib/opal-webpack-loader/compile_worker.rb', line 7 def cache @cache end |
#compiler_options_digest ⇒ Object (readonly)
Returns the value of attribute compiler_options_digest.
7 8 9 |
# File 'lib/opal-webpack-loader/compile_worker.rb', line 7 def end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
7 8 9 |
# File 'lib/opal-webpack-loader/compile_worker.rb', line 7 def number @number end |
#tempfile ⇒ Object (readonly)
Returns the value of attribute tempfile.
7 8 9 |
# File 'lib/opal-webpack-loader/compile_worker.rb', line 7 def tempfile @tempfile end |
Instance Method Details
#==(other_number) ⇒ Object
25 26 27 |
# File 'lib/opal-webpack-loader/compile_worker.rb', line 25 def ==(other_number) number == other_number end |
#start ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/opal-webpack-loader/compile_worker.rb', line 29 def start $PROGRAM_NAME = "owl compile worker #{number}" SIGNALS.each { |sig| trap(sig, 'IGNORE') } trap('CHLD', 'DEFAULT') alive = true %w[TERM INT].each { |sig| trap(sig) { exit(0) } } trap('QUIT') do alive = false begin @socket.close rescue nil end end ret = nil i = 0 while alive && @master_pid == Process.ppid tempfile.chmod(i += 1) if ret begin client = @socket.accept_nonblock request = client.gets("\x04") if request.start_with?('command:stop') OpalWebpackLoader::CompileServer.unlink_socket_on_exit Process.kill('TERM', @master_pid) exit(0) else result = compile(request) client.write result client.flush client.close end rescue Errno::EAGAIN, Errno::EWOULDBLOCK end end tempfile.chmod(i += 1) ret = begin IO.select([@socket], nil, nil, OpalWebpackLoader::CompileServer::TIMEOUT / 2) || next rescue Errno::EBADF end end end |