Gems, workers, networking, oh my!

This commit is contained in:
2026-04-21 12:57:05 -05:00
parent dc9e737587
commit e97e5cc862
7 changed files with 348 additions and 6 deletions

View File

@@ -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