Skip to content

Commit

Permalink
Make upsync call concurrent
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcastil committed Nov 21, 2024
1 parent c3e5185 commit b54f2b6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/wafris.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,22 @@ def send_upsync_requests(requests_array)

url_and_api_key = @configuration.upsync_url + "/" + @configuration.api_key

LogSuppressor.puts_log("Beginning upsync request thread...")
response = HTTParty.post(
url_and_api_key,
body: body,
headers: headers,
timeout: 10
timeout: 5
)

if response.code == 200
@configuration.upsync_status = "Complete"
LogSuppressor.puts_log("Upsync request thread complete.")
else
LogSuppressor.puts_log("Upsync Error. HTTP Response: #{response.code}")
LogSuppressor.puts_log("Upsync Thread Error. HTTP Response: #{response.code}")
end
rescue HTTParty::Error => e
LogSuppressor.puts_log("Upsync Error. Failed to send upsync requests: #{e.message}")
LogSuppressor.puts_log("Upsync Thread Error. Failed to send upsync requests: #{e.message}")
end

# This method is used to queue upsync requests. It takes in several parameters including:
Expand All @@ -220,7 +222,7 @@ def queue_upsync_request(request, treatment, category, rule)
@configuration.upsync_queue = []
@configuration.last_upsync_timestamp = Time.now.to_i

send_upsync_requests(requests_array)
Thread.new { send_upsync_requests(requests_array) }
end

@configuration.upsync_status = "Enabled"
Expand Down Expand Up @@ -277,7 +279,8 @@ def downsync_db(db_rule_category, current_filename = nil)
response = HTTParty.get(
uri,
follow_redirects: true, # Enable following redirects
max_redirects: 2 # Maximum number of redirects to follow
max_redirects: 2, # Maximum number of redirects to follow
timeout: 20
)

# TODO: What to do if timeout
Expand Down

0 comments on commit b54f2b6

Please sign in to comment.