mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-05-06 09:28:18 +00:00
Gems, workers, networking, oh my!
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
module W3DHubLauncher
|
||||
class Worker
|
||||
Response = Data.define(:status, :request_id, :data)
|
||||
|
||||
def initialize
|
||||
@threads = []
|
||||
@requests = []
|
||||
|
||||
# next available request_id to assign incoming requests
|
||||
@request_id = 0
|
||||
|
||||
# listen for requests from frontend
|
||||
listener = Thread.new { listen }
|
||||
@@ -10,15 +16,28 @@ module W3DHubLauncher
|
||||
# connect to and monitor Backend web service
|
||||
@threads << Thread.new { backend_websocket }
|
||||
|
||||
Ractor.main.send({ message: "3 o'clock 'nd all's well!" })
|
||||
@w3dhub_api = W3DHubLauncher::W3DHubApi.new
|
||||
|
||||
listener.join
|
||||
end
|
||||
|
||||
def listen
|
||||
loop do
|
||||
request = Ractor.receive
|
||||
pp request
|
||||
query = Ractor.receive
|
||||
pp query
|
||||
|
||||
case query.type
|
||||
when Request::FETCH_URL
|
||||
when Request::DOWNLOAD_URL
|
||||
when Request::W3DHUB_API_CALL
|
||||
Async do
|
||||
result = @w3dhub_api.send(query.data[:call], *(query.data[:arguments] || []))
|
||||
response = Response.new(result.okay? ? Request::STATUS_COMPLETE : Request::STATUS_ERROR, query.request_id, result)
|
||||
Ractor.main.send(response)
|
||||
end
|
||||
else
|
||||
raise "UNKNOWN REQUEST"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user