Tidy up imports/requires to use Zeitwerk
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -10,6 +10,7 @@ gem "aws-sdk-ecr"
|
|||||||
gem "simplecov", require: false, group: :test
|
gem "simplecov", require: false, group: :test
|
||||||
|
|
||||||
gem "ffi-rzmq"
|
gem "ffi-rzmq"
|
||||||
|
gem "zeitwerk"
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# gem "bundler"
|
# gem "bundler"
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ GEM
|
|||||||
thread_safe (0.3.6)
|
thread_safe (0.3.6)
|
||||||
tzinfo (1.2.5)
|
tzinfo (1.2.5)
|
||||||
thread_safe (~> 0.1)
|
thread_safe (~> 0.1)
|
||||||
|
zeitwerk (2.2.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
@@ -76,6 +77,7 @@ DEPENDENCIES
|
|||||||
rake
|
rake
|
||||||
rugged
|
rugged
|
||||||
simplecov
|
simplecov
|
||||||
|
zeitwerk
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.17.2
|
1.17.2
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class PipelineClient
|
|||||||
def open_socket
|
def open_socket
|
||||||
@socket = context.socket(ZMQ::REQ)
|
@socket = context.socket(ZMQ::REQ)
|
||||||
@socket.setsockopt(ZMQ::LINGER, 0)
|
@socket.setsockopt(ZMQ::LINGER, 0)
|
||||||
@socket.connect("tcp://localhost:5566")
|
@socket.connect("tcp://localhost:5555")
|
||||||
end
|
end
|
||||||
|
|
||||||
def close_socket
|
def close_socket
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ worker_identity = ARGV[0]
|
|||||||
channel_address = ARGV[1]
|
channel_address = ARGV[1]
|
||||||
env_base = ARGV[2]
|
env_base = ARGV[2]
|
||||||
|
|
||||||
server = Pipeline::Rpc::Worker.new(worker_identity, channel_address, env_base)
|
daemon = Pipeline::Rpc::Worker::Daemon.new(worker_identity, channel_address, env_base)
|
||||||
server.listen
|
daemon.listen
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ require 'yaml'
|
|||||||
require 'json'
|
require 'json'
|
||||||
require 'ffi-rzmq'
|
require 'ffi-rzmq'
|
||||||
|
|
||||||
|
require "zeitwerk"
|
||||||
|
loader = Zeitwerk::Loader.for_gem
|
||||||
|
loader.setup # ready!
|
||||||
|
|
||||||
|
|
||||||
module Pipeline
|
module Pipeline
|
||||||
|
|
||||||
def self.load_config(config_path)
|
def self.load_config(config_path)
|
||||||
@@ -76,25 +81,25 @@ module Pipeline
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "pipeline/rpc/router"
|
# require "pipeline/rpc/router"
|
||||||
require "pipeline/rpc/worker"
|
# require "pipeline/rpc/worker"
|
||||||
require "pipeline/analyzer_repo"
|
# require "pipeline/analyzer_repo"
|
||||||
require "pipeline/container_repo"
|
# require "pipeline/container_repo"
|
||||||
require "pipeline/validation/check_invokable"
|
# require "pipeline/validation/check_invokable"
|
||||||
require "pipeline/validation/check_environment_invariants"
|
# require "pipeline/validation/check_environment_invariants"
|
||||||
require "pipeline/validation/check_fixtures"
|
# require "pipeline/validation/check_fixtures"
|
||||||
require "pipeline/validation/fixture_check_error.rb"
|
# require "pipeline/validation/fixture_check_error.rb"
|
||||||
require "pipeline/validation/validate_build"
|
# require "pipeline/validation/validate_build"
|
||||||
require "pipeline/util/container_driver"
|
# require "pipeline/util/container_driver"
|
||||||
require "pipeline/util/runc_configurator"
|
# require "pipeline/util/runc_configurator"
|
||||||
require "pipeline/util/img_wrapper"
|
# require "pipeline/util/img_wrapper"
|
||||||
require "pipeline/util/runc_wrapper"
|
# require "pipeline/util/runc_wrapper"
|
||||||
require "pipeline/util/external_command"
|
# require "pipeline/util/external_command"
|
||||||
require "pipeline/util/log_collector"
|
# require "pipeline/util/log_collector"
|
||||||
require "pipeline/build/build_image"
|
# require "pipeline/build/build_image"
|
||||||
require "pipeline/build/publish_image"
|
# require "pipeline/build/publish_image"
|
||||||
require "pipeline/build/container_build"
|
# require "pipeline/build/container_build"
|
||||||
require "pipeline/build/analyzer_build"
|
# require "pipeline/build/analyzer_build"
|
||||||
require "pipeline/build/test_runner_build"
|
# require "pipeline/build/test_runner_build"
|
||||||
require "pipeline/runtime/runtime_environment"
|
# require "pipeline/runtime/runtime_environment"
|
||||||
require "pipeline/runtime/analysis_run"
|
# require "pipeline/runtime/analysis_run"
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ module Pipeline::Rpc
|
|||||||
def initialize(zmq_context)
|
def initialize(zmq_context)
|
||||||
@zmq_context = zmq_context
|
@zmq_context = zmq_context
|
||||||
|
|
||||||
@front_end_port = 5566
|
@front_end_port = 5555
|
||||||
@front_end = FrontEndSocket.new(zmq_context, @front_end_port)
|
@front_end = FrontEndSocket.new(zmq_context, @front_end_port)
|
||||||
|
|
||||||
@public_hostname = "localhost"
|
@public_hostname = "localhost"
|
||||||
@response_port = 5555
|
@response_port = 5556
|
||||||
@response_socket = ResponseSocket.new(zmq_context, @response_port)
|
@response_socket = ResponseSocket.new(zmq_context, @response_port)
|
||||||
|
|
||||||
@poller = ChannelPoller.new
|
@poller = ChannelPoller.new
|
||||||
@@ -23,9 +23,9 @@ module Pipeline::Rpc
|
|||||||
@backend_channels = {}
|
@backend_channels = {}
|
||||||
|
|
||||||
@work_channel_ports = {
|
@work_channel_ports = {
|
||||||
static_analyzers: 5577,
|
static_analyzers: 5560,
|
||||||
test_runners: 5578,
|
test_runners: 5561,
|
||||||
representers: 5579
|
representers: 5562
|
||||||
}
|
}
|
||||||
@work_channel_ports.each do |type, port|
|
@work_channel_ports.each do |type, port|
|
||||||
bind_address = "tcp://*:#{@work_channel_ports[type]}"
|
bind_address = "tcp://*:#{@work_channel_ports[type]}"
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
class Pipeline::Rpc::Worker
|
|
||||||
|
|
||||||
attr_reader :identity, :context, :incoming, :outgoing, :environment
|
|
||||||
|
|
||||||
def initialize(identity, channel_address, env_base)
|
|
||||||
@identity = identity
|
|
||||||
channel_address = URI(channel_address)
|
|
||||||
@control_queue = "#{channel_address.scheme}://#{channel_address.host}:#{channel_address.port}"
|
|
||||||
@channel = channel_address.path[1..]
|
|
||||||
@context = ZMQ::Context.new(1)
|
|
||||||
@incoming = context.socket(ZMQ::PULL)
|
|
||||||
@notifications = context.socket(ZMQ::SUB)
|
|
||||||
@notifications.setsockopt(ZMQ::SUBSCRIBE, "")
|
|
||||||
@environment = Pipeline::Runtime::RuntimeEnvironment.new(env_base)
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup
|
|
||||||
@setup = context.socket(ZMQ::REQ)
|
|
||||||
@setup.setsockopt(ZMQ::LINGER, 0)
|
|
||||||
puts @control_queue
|
|
||||||
@setup.connect(@control_queue)
|
|
||||||
request = {
|
|
||||||
action: "configure_worker",
|
|
||||||
channel: @channel
|
|
||||||
}
|
|
||||||
@setup.send_string(request.to_json)
|
|
||||||
msg = ""
|
|
||||||
@setup.recv_string(msg)
|
|
||||||
msg = JSON.parse(msg)
|
|
||||||
puts "Bootstrap with #{msg}"
|
|
||||||
@setup.close
|
|
||||||
|
|
||||||
environment.prepare
|
|
||||||
|
|
||||||
action = Pipeline::Rpc::ConfigureAction.new
|
|
||||||
action.environment = environment
|
|
||||||
action.request = msg
|
|
||||||
action.invoke
|
|
||||||
|
|
||||||
response_address = msg["channel"]["response_address"]
|
|
||||||
request_address = msg["channel"]["workqueue_address"]
|
|
||||||
notification_address = msg["channel"]["notification_address"]
|
|
||||||
@outgoing = context.socket(ZMQ::PUB)
|
|
||||||
@outgoing.connect(response_address)
|
|
||||||
incoming.connect(request_address)
|
|
||||||
@notifications.connect(notification_address)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def listen
|
|
||||||
setup
|
|
||||||
|
|
||||||
@incoming_wrapper = SocketWrapper.new(incoming)
|
|
||||||
@noificationincoming_wrapper = NotificationSocketWrapper.new(@notifications)
|
|
||||||
|
|
||||||
@poller = Pipeline::Rpc::ChannelPoller.new
|
|
||||||
@poller.register(@incoming_wrapper)
|
|
||||||
@poller.register(@noificationincoming_wrapper)
|
|
||||||
|
|
||||||
loop do
|
|
||||||
msg = []
|
|
||||||
|
|
||||||
@poller.listen_for_messages do |action_task|
|
|
||||||
unless action_task.nil?
|
|
||||||
action_task.environment = environment
|
|
||||||
result = action_task.invoke
|
|
||||||
if result && result["return_address"]
|
|
||||||
outgoing.send_string(result.to_json)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
79
lib/pipeline/rpc/worker/daemon.rb
Normal file
79
lib/pipeline/rpc/worker/daemon.rb
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
module Pipeline::Rpc::Worker
|
||||||
|
|
||||||
|
class Daemon
|
||||||
|
|
||||||
|
attr_reader :identity, :context, :incoming, :outgoing, :environment
|
||||||
|
|
||||||
|
def initialize(identity, channel_address, env_base)
|
||||||
|
@identity = identity
|
||||||
|
channel_address = URI(channel_address)
|
||||||
|
@control_queue = "#{channel_address.scheme}://#{channel_address.host}:#{channel_address.port}"
|
||||||
|
@channel = channel_address.path[1..]
|
||||||
|
@context = ZMQ::Context.new(1)
|
||||||
|
@incoming = context.socket(ZMQ::PULL)
|
||||||
|
@notifications = context.socket(ZMQ::SUB)
|
||||||
|
@notifications.setsockopt(ZMQ::SUBSCRIBE, "")
|
||||||
|
@environment = Pipeline::Runtime::RuntimeEnvironment.new(env_base)
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@setup = context.socket(ZMQ::REQ)
|
||||||
|
@setup.setsockopt(ZMQ::LINGER, 0)
|
||||||
|
puts @control_queue
|
||||||
|
@setup.connect(@control_queue)
|
||||||
|
request = {
|
||||||
|
action: "configure_worker",
|
||||||
|
channel: @channel
|
||||||
|
}
|
||||||
|
@setup.send_string(request.to_json)
|
||||||
|
msg = ""
|
||||||
|
@setup.recv_string(msg)
|
||||||
|
msg = JSON.parse(msg)
|
||||||
|
puts "Bootstrap with #{msg}"
|
||||||
|
@setup.close
|
||||||
|
|
||||||
|
environment.prepare
|
||||||
|
|
||||||
|
action = Pipeline::Rpc::Worker::ConfigureAction.new
|
||||||
|
action.environment = environment
|
||||||
|
action.request = msg
|
||||||
|
action.invoke
|
||||||
|
|
||||||
|
response_address = msg["channel"]["response_address"]
|
||||||
|
request_address = msg["channel"]["workqueue_address"]
|
||||||
|
notification_address = msg["channel"]["notification_address"]
|
||||||
|
@outgoing = context.socket(ZMQ::PUB)
|
||||||
|
@outgoing.connect(response_address)
|
||||||
|
incoming.connect(request_address)
|
||||||
|
@notifications.connect(notification_address)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def listen
|
||||||
|
setup
|
||||||
|
|
||||||
|
@incoming_wrapper = Pipeline::Rpc::Worker::WorkSocketWrapper.new(incoming)
|
||||||
|
@noificationincoming_wrapper = Pipeline::Rpc::Worker::NotificationSocketWrapper.new(@notifications)
|
||||||
|
|
||||||
|
@poller = Pipeline::Rpc::ChannelPoller.new
|
||||||
|
@poller.register(@incoming_wrapper)
|
||||||
|
@poller.register(@noificationincoming_wrapper)
|
||||||
|
|
||||||
|
loop do
|
||||||
|
msg = []
|
||||||
|
|
||||||
|
@poller.listen_for_messages do |action_task|
|
||||||
|
unless action_task.nil?
|
||||||
|
action_task.environment = environment
|
||||||
|
result = action_task.invoke
|
||||||
|
if result && result["return_address"]
|
||||||
|
outgoing.send_string(result.to_json)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -17,11 +17,11 @@ module Pipeline::Rpc::Worker
|
|||||||
|
|
||||||
puts "HERE #{action}"
|
puts "HERE #{action}"
|
||||||
if action == "configure"
|
if action == "configure"
|
||||||
a = Pipeline::Rpc::ConfigureAction.new
|
a = Pipeline::Rpc::Worker::ConfigureAction.new
|
||||||
a.request = request
|
a.request = request
|
||||||
a
|
a
|
||||||
elsif action == "analyze_iteration" || action == "test_solution"
|
elsif action == "analyze_iteration" || action == "test_solution"
|
||||||
a = Pipeline::Rpc::AnalyzeAction.new(request, return_address)
|
a = Pipeline::Rpc::Worker::AnalyzeAction.new(request, return_address)
|
||||||
a
|
a
|
||||||
else
|
else
|
||||||
puts "HERE ELSE: #{request}"
|
puts "HERE ELSE: #{request}"
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ module Pipeline::Rpc::Worker
|
|||||||
action = request["action"]
|
action = request["action"]
|
||||||
|
|
||||||
if action == "configure"
|
if action == "configure"
|
||||||
Pipeline::Rpc::ConfigureAction.new
|
ConfigureAction.new
|
||||||
elsif action == "analyze_iteration" || action == "test_solution"
|
elsif action == "analyze_iteration" || action == "test_solution"
|
||||||
a = Pipeline::Rpc::AnalyzeAction.new(request, return_address)
|
a = AnalyzeAction.new(request, return_address)
|
||||||
a.request = request
|
a.request = request
|
||||||
a
|
a
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class FixtureCheckError < StandardError
|
module Pipeline::Validation
|
||||||
|
class FixtureCheckError < StandardError
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
super
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user