-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbase_job.rb
More file actions
33 lines (26 loc) · 1000 Bytes
/
base_job.rb
File metadata and controls
33 lines (26 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module AnswerAnalysis
class BaseJob < ApplicationJob
NUMBER_OF_RUNS = 3
MAX_RETRIES = 5
retry_on Aws::Errors::ServiceError, wait: 1.minute, attempts: MAX_RETRIES
private
def eligible_for_answer_analysis?(answer_id)
eligible = Answer.status_answered.exists?(id: answer_id)
unless eligible
logger.warn("Couldn't find an answer #{answer_id} that was eligible for auto-evaluation")
end
eligible
end
def quota_limit_reached?
key = "auto_evaluations_count_#{Time.current.beginning_of_hour.to_i}"
max_evaluations = Rails.configuration.max_auto_evaluations_per_hour
# fallback to 1 in scenarios where we have a null cache (test environment) and this returns nil
count = Rails.cache.increment(key, expires_in: 1.hour) || 1
if count > max_evaluations
logger.warn("Auto-evaluation quota limit of #{max_evaluations} evaluations per hour reached")
return true
end
false
end
end
end