-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dev-support/test-fixes
- Loading branch information
Showing
109 changed files
with
4,571 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class Metrics::DashboardController < ApplicationController | ||
before_action :require_demo | ||
|
||
def show | ||
no_cache | ||
|
||
@metrics = Metric.includes(:user).where("created_at > ?", 1.hour.ago).order(created_at: :desc) | ||
|
||
begin | ||
render :show, layout: "plain_application" | ||
rescue StandardError => error | ||
Rails.logger.error(error.full_message) | ||
raise error.full_message | ||
end | ||
end | ||
|
||
private | ||
|
||
def require_demo | ||
redirect_to "/unauthorized" unless Rails.deploy_env?(:demo) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
class Metrics::V2::LogsController < ApplicationController | ||
skip_before_action :verify_authentication | ||
|
||
def create | ||
metric = Metric.create_metric_from_rest(self, allowed_params, current_user) | ||
failed_metric_info = metric&.errors.inspect || allowed_params[:message] | ||
Rails.logger.info("Failed to create metric #{failed_metric_info}") unless metric&.valid? | ||
|
||
if (metric.metric_type === 'error') | ||
error_info = { | ||
name: metric.metric_name, | ||
class: metric.metric_class, | ||
attrs: metric.metric_attributes, | ||
created_at: metric.created_at, | ||
uuid: metric.uuid, | ||
} | ||
error = StandardError.new(error_info) | ||
Raven.capture_exception(error) | ||
end | ||
|
||
head :ok | ||
end | ||
|
||
def allowed_params | ||
params.require(:metric).permit(:uuid, | ||
:name, | ||
:group, | ||
:message, | ||
:type, | ||
:product, | ||
:app_name, | ||
:metric_attributes, | ||
:additional_info, | ||
:sent_to, | ||
:sent_to_info, | ||
:relevant_tables_info, | ||
:start, | ||
:end, | ||
:duration | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
# This job will search for and reprocess unfinished Batch Processes nightly. | ||
# Search Criteria is for Batch Processes that are in an unfinished state ('PRE_PROCESSING', 'PROCESSING') & | ||
# have a created_at date/time that is greater than the ERROR_DELAY defined within batch_process.rb | ||
class BatchProcessRescueJob < CaseflowJob | ||
queue_with_priority :low_priority | ||
|
||
# :reek:FeatureEnvy | ||
def perform | ||
batches = BatchProcess.needs_reprocessing | ||
if batches.any? | ||
batches.each do |batch| | ||
begin | ||
batch.process_batch! | ||
rescue StandardError => error | ||
log_error(error, extra: { active_job_id: job_id.to_s, job_time: Time.zone.now.to_s }) | ||
slack_msg = "Error running #{self.class.name}. Error: #{error.message}. Active Job ID: #{job_id}." | ||
slack_msg += " See Sentry event #{Raven.last_event_id}." if Raven.last_event_id.present? | ||
slack_service.send_notification("[ERROR] #{slack_msg}", self.class.to_s) | ||
next | ||
end | ||
end | ||
else | ||
Rails.logger.info("No Unfinished Batches Could Be Identified. Time: #{Time.zone.now}.") | ||
end | ||
end | ||
end |
82 changes: 82 additions & 0 deletions
82
app/jobs/batch_processes/priority_ep_sync_batch_process_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# frozen_string_literal: true | ||
|
||
class PriorityEpSyncBatchProcessJob < CaseflowJob | ||
queue_with_priority :low_priority | ||
|
||
# Using macro-style definition. The locking scope will be TheClass#method and only one method can run at any | ||
# given time. | ||
include RedisMutex::Macro | ||
|
||
# Default options for RedisMutex#with_lock | ||
# :block => 1 # Specify in seconds how long you want to wait for the lock to be released. | ||
# # Specify 0 if you need non-blocking sematics and return false immediately. (default: 1) | ||
# :sleep => 0.1 # Specify in seconds how long the polling interval should be when :block is given. | ||
# # It is NOT recommended to go below 0.01. (default: 0.1) | ||
# :expire => 10 # Specify in seconds when the lock should be considered stale when something went wrong | ||
# # with the one who held the lock and failed to unlock. (default: 10) | ||
# | ||
# RedisMutex.with_lock("PriorityEpSyncBatchProcessJob", block: 60, expire: 100) | ||
# Key => "PriorityEpSyncBatchProcessJob" | ||
|
||
JOB_DURATION ||= ENV["BATCH_PROCESS_JOB_DURATION"].to_i.minutes | ||
SLEEP_DURATION ||= ENV["BATCH_PROCESS_SLEEP_DURATION"].to_i | ||
|
||
# Attempts to create & process batches for 50 minutes | ||
# There will be a 5 second rest between each iteration | ||
# Job will end if there are no records are left to batch | ||
|
||
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity | ||
def perform | ||
setup_job | ||
loop do | ||
break if job_running_past_expected_end_time? || should_stop_job | ||
|
||
begin | ||
batch = nil | ||
RedisMutex.with_lock("PriorityEpSyncBatchProcessJob", block: 60, expire: 100) do | ||
batch = ActiveRecord::Base.transaction do | ||
records_to_batch = PriorityEpSyncBatchProcess.find_records_to_batch | ||
next if records_to_batch.empty? | ||
|
||
PriorityEpSyncBatchProcess.create_batch!(records_to_batch) | ||
end | ||
end | ||
|
||
batch ? batch.process_batch! : stop_job(log_no_records_found: true) | ||
|
||
sleep(SLEEP_DURATION) | ||
rescue StandardError => error | ||
log_error(error, extra: { job_id: job_id.to_s, job_time: Time.zone.now.to_s }) | ||
slack_msg = "Error running #{self.class.name}. Error: #{error.message}. Active Job ID: #{job_id}." | ||
slack_msg += " See Sentry event #{Raven.last_event_id}." if Raven.last_event_id.present? | ||
slack_service.send_notification("[ERROR] #{slack_msg}", self.class.to_s) | ||
stop_job | ||
end | ||
end | ||
end | ||
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity | ||
|
||
private | ||
|
||
attr_accessor :job_expected_end_time, :should_stop_job | ||
|
||
def setup_job | ||
RequestStore.store[:current_user] = User.system_user | ||
@should_stop_job = false | ||
@job_expected_end_time = Time.zone.now + JOB_DURATION | ||
end | ||
|
||
def job_running_past_expected_end_time? | ||
Time.zone.now > job_expected_end_time | ||
end | ||
|
||
# :reek:BooleanParameter | ||
# :reek:ControlParameter | ||
def stop_job(log_no_records_found: false) | ||
self.should_stop_job = true | ||
if log_no_records_found | ||
Rails.logger.info("#{self.class} Cannot Find Any Records to Batch."\ | ||
" Job will be enqueued again at the top of the hour. Active Job ID: #{job_id}. Time: #{Time.zone.now}") | ||
end | ||
end | ||
end |
Oops, something went wrong.