mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2026-01-23 15:21:56 +00:00
refactor: move backend status handling to own function
This commit is contained in:
@@ -45,32 +45,19 @@ module BackendInfo
|
|||||||
body = response.body
|
body = response.body
|
||||||
status_json = CompanionData.from_json(body)
|
status_json = CompanionData.from_json(body)
|
||||||
if status_json.blocked
|
if status_json.blocked
|
||||||
@@check_mutex.synchronize do
|
updated_ends, updated_status = self.set_status(index, updated_ends, updated_status, Status::Blocked, true)
|
||||||
updated_status[index] = Status::Blocked.to_i
|
|
||||||
updated_ends.push(index)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
@@check_mutex.synchronize do
|
updated_ends, updated_status = self.set_status(index, updated_ends, updated_status, Status::Working, true)
|
||||||
updated_status[index] = Status::Working.to_i
|
|
||||||
updated_ends.push(index)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@check_mutex.synchronize do
|
updated_ends, updated_status = self.set_status(index, updated_ends, updated_status, Status::Working, true)
|
||||||
updated_status[index] = Status::Working.to_i
|
|
||||||
updated_ends.push(index)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
generate_csp([companion.public_url, companion.i2p_public_url], index)
|
self.generate_csp([companion.public_url, companion.i2p_public_url], index)
|
||||||
else
|
else
|
||||||
@@check_mutex.synchronize do
|
_, updated_status = self.set_status(index, updated_ends, updated_status, Status::Dead, false)
|
||||||
updated_status[index] = Status::Dead.to_i
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
@@check_mutex.synchronize do
|
_, updated_status = self.set_status(index, updated_ends, updated_status, Status::Dead, false)
|
||||||
updated_status[index] = Status::Dead.to_i
|
|
||||||
end
|
|
||||||
ensure
|
ensure
|
||||||
LOGGER.trace("Invidious companion: Done Index: \"#{index}\"")
|
LOGGER.trace("Invidious companion: Done Index: \"#{index}\"")
|
||||||
channels.send(nil)
|
channels.send(nil)
|
||||||
@@ -94,6 +81,14 @@ module BackendInfo
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private def set_status(index, updated_ends, updated_status, status, push = false)
|
||||||
|
@@check_mutex.synchronize do
|
||||||
|
updated_status[index] = status.to_i
|
||||||
|
updated_ends.push(index) if push
|
||||||
|
end
|
||||||
|
return {updated_ends, updated_status}
|
||||||
|
end
|
||||||
|
|
||||||
def get_status
|
def get_status
|
||||||
# Shouldn't need to lock since we never edit this array, only change the pointer.
|
# Shouldn't need to lock since we never edit this array, only change the pointer.
|
||||||
return @@status
|
return @@status
|
||||||
|
|||||||
Reference in New Issue
Block a user