Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhgchgli0718 committed Aug 20, 2022
1 parent 5dbae6e commit 4b2d36a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.1
1.3.2
21 changes: 14 additions & 7 deletions lib/GoogleAPI.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ def request(url, method = "GET", data = nil, retryCount = 0)
result = JSON.parse(response)

if !result["error"].nil?
if retryCount >= 10
raise "Could not connect to #{tokenURI}, key id: #{keyID}, error message: #{response}"
# Quota exceeded for quota metric 'Write requests' and limit 'Write requests per minute per user
if result["error"]["code"] == 429
puts "[GoogleAPI] Reached Rate Limited, sleep 30 secs..."
sleep(30)
return request(url, method, data, 0)
else
@token = generateJWT()
message = "JWT Invalid, retry. (#{retryCount + 1})"
logger.logWarn(message)
puts "[GoogleAPI] #{message}"
return request(url, method, data, retryCount + 1)
if retryCount >= 10
raise "Could not connect to #{tokenURI}, key id: #{keyID}, error message: #{response}"
else
@token = generateJWT()
message = "JWT Invalid, retry. (#{retryCount + 1})"
logger.logWarn(message)
puts "[GoogleAPI] #{message}"
return request(url, method, data, retryCount + 1)
end
end
else
return result
Expand Down
12 changes: 9 additions & 3 deletions lib/Processors/GoogleSheetProcessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def processReviews(reviews, platform)
end
end

values = []
filterReviews.each do |review|
cols = []
formatValues.each do |formatValue|
Expand All @@ -89,10 +90,15 @@ def processReviews(reviews, platform)

cols.append(formatValue)
end

puts "[GoogleSheetProcessor] insert #{cols} to #{sheetID}-#{sheetName}"
values.append(cols)
end

googleAPI.request("https://sheets.googleapis.com/v4/spreadsheets/#{sheetID}/values/#{sheetName}:append?valueInputOption=RAW", "POST", {:values => [cols]})
page = 1
limit = 500
values.each_slice(limit) do |value|
puts "[GoogleSheetProcessor] Insert rows(#{page}/#{(values.length/limit).ceil + 1}) to #{sheetID}-#{sheetName}"
page += 1
googleAPI.request("https://sheets.googleapis.com/v4/spreadsheets/#{sheetID}/values/#{sheetName}!A1:append?valueInputOption=RAW", "POST", {:values => value})
end

return reviews
Expand Down
1 change: 1 addition & 0 deletions lib/Processors/SlackProcessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def processReviews(reviews, platform)
logger.logError(payload)
logger.logError(result)
if result[:message] == "ratelimited"
puts "[SlackProcessor] Reached Rate Limited, sleep 1 sec..."
sleep(1)
pendingPayloads.insert(0, payload)
end
Expand Down

0 comments on commit 4b2d36a

Please sign in to comment.