Spaces:
Sleeping
Sleeping
j
commited on
Commit
·
6cd6178
1
Parent(s):
5a4097e
added retry for 500 errors in get_job_status
Browse files
reascripts/ReaSpeech/source/ReaSpeechWorker.lua
CHANGED
@@ -113,11 +113,28 @@ function ReaSpeechWorker:cancel_job(job_id)
|
|
113 |
end)
|
114 |
end
|
115 |
|
116 |
-
function ReaSpeechWorker:get_job_status(job_id)
|
|
|
|
|
|
|
|
|
117 |
local url_path = "jobs/" .. job_id
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
end)
|
122 |
end
|
123 |
|
|
|
113 |
end)
|
114 |
end
|
115 |
|
116 |
+
function ReaSpeechWorker:get_job_status(job_id, retry_count)
|
117 |
+
retry_count = retry_count or 0
|
118 |
+
local max_retries = 5
|
119 |
+
local retry_delay = 1 * (2 ^ retry_count) -- Exponential backoff
|
120 |
+
|
121 |
local url_path = "jobs/" .. job_id
|
122 |
+
|
123 |
+
ReaSpeechAPI:fetch_json(url_path, 'GET', function(error_message)
|
124 |
+
if error_message:match("500") and retry_count < max_retries then
|
125 |
+
app:debug("Got 500 error, retrying in " .. retry_delay .. " seconds. Retry " .. (retry_count + 1) .. " of " .. max_retries)
|
126 |
+
reaper.defer(function()
|
127 |
+
self:get_job_status(job_id, retry_count + 1)
|
128 |
+
end)
|
129 |
+
else
|
130 |
+
self:handle_error(self.active_job, error_message)
|
131 |
+
self.active_job = nil
|
132 |
+
end
|
133 |
+
end, function(response)
|
134 |
+
|
135 |
+
if self:handle_job_status(self.active_job, response) then
|
136 |
+
self.active_job = nil
|
137 |
+
end
|
138 |
end)
|
139 |
end
|
140 |
|