Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/jobs/get_usps_proofing_results_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class GetUspsProofingResultsJob < ApplicationJob
]

queue_as :default
include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: 'get_usps_proofing_results',
)

discard_on GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError

def email_analytics_attributes(enrollment)
{
Expand Down
9 changes: 9 additions & 0 deletions app/jobs/gpo_daily_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
class GpoDailyJob < ApplicationJob
queue_as :low

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "gpo-daily-job-#{arguments.first}" },
)

discard_on GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError

# Enqueue a test letter every day, but only upload letters on working weekdays
def perform(date)
GpoDailyTestSender.new.run
Expand Down
9 changes: 9 additions & 0 deletions app/jobs/phone_number_opt_out_sync_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
class PhoneNumberOptOutSyncJob < ApplicationJob
queue_as :long_running
include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> do
rounded = TimeService.round_time(time: arguments.first, interval: 1.hour)
"phone-number-opt-out-sync-#{rounded.to_i}"
end,
)

def perform(_now)
all_phone_numbers = Set.new
Expand Down
11 changes: 11 additions & 0 deletions app/jobs/psql_stats_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
class PsqlStatsJob < ApplicationJob
queue_as :default
include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> do
rounded = TimeService.round_time(time: arguments.first, interval: 1.minute)
"psql_bloat_statistics-#{rounded.to_i}"
end,
)

discard_on GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError

# gather data on bloat for each table
# https://github.com/ioguix/pgsql-bloat-estimation/blob/master/table/table_bloat.sql
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/agency_invoice_iaa_supplement_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ module Reports
class AgencyInvoiceIaaSupplementReport < BaseReport
REPORT_NAME = 'agency-invoice-iaa-supplemement-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
raw_results = IaaReportingHelper.iaas.flat_map do |iaa|
Db::MonthlySpAuthCount::UniqueMonthlyAuthCountsByIaa.call(
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/agency_invoice_issuer_supplement_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ module Reports
class AgencyInvoiceIssuerSupplementReport < BaseReport
REPORT_NAME = 'agency-invoice-issuer-supplemement-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
raw_results = service_providers.flat_map do |service_provider|
transaction_with_timeout do
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/agency_user_counts_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class AgencyUserCountsReport < BaseReport
REPORT_NAME = 'agency-user-counts-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
user_counts = transaction_with_timeout do
Db::AgencyIdentity::AgencyUserCounts.call
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/agreement_summary_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class AgreementSummaryReport < BaseReport
REPORT_NAME = 'agreement-summary-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
csv = build_report

Expand Down
3 changes: 3 additions & 0 deletions app/jobs/reports/base_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module Reports
class BaseReport < ApplicationJob
queue_as :long_running

# We use good_job's concurrency features to cancel "extra" or duplicative runs of the same job
discard_on GoodJob::ActiveJobExtensions::Concurrency::ConcurrencyExceededError

def self.transaction_with_timeout(rails_env = Rails.env)
# rspec-rails's use_transactional_tests does not seem to act as expected when switching
# connections mid-test, so we just skip for now :[
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/combined_invoice_supplement_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class CombinedInvoiceSupplementReport < BaseReport
REPORT_NAME = 'combined-invoice-supplement-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
iaas = IaaReportingHelper.iaas

Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/daily_auths_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ module Reports
class DailyAuthsReport < BaseReport
REPORT_NAME = 'daily-auths-report'

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

attr_reader :report_date

def perform(report_date)
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/daily_dropoffs_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class DailyDropoffsReport < BaseReport
REPORT_NAME = 'daily-dropoffs-report'

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

attr_reader :report_date

def perform(report_date)
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/deleted_user_accounts_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ module Reports
class DeletedUserAccountsReport < BaseReport
REPORT_NAME = 'deleted-user-accounts-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
configs = IdentityConfig.store.deleted_user_accounts_report_configs
configs.each do |report_hash|
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/doc_auth_drop_off_rates_per_sprint_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class DocAuthDropOffRatesPerSprintReport < BaseReport
REPORT_NAME = 'doc-auth-drop-offs-per-sprint-report'.freeze
FIRST_SPRINT_DATE = '10-10-2019'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
ret = generate_report
save_report(REPORT_NAME, ret.join, extension: 'txt')
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/doc_auth_drop_off_rates_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class DocAuthDropOffRatesReport < BaseReport
REPORT_NAME = 'doc-auth-drop-off-rates-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
ret = generate_report
save_report(REPORT_NAME, ret.join, extension: 'txt')
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/doc_auth_funnel_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class DocAuthFunnelReport < BaseReport
REPORT_NAME = 'doc-auth-funnel-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
report = transaction_with_timeout do
Db::DocAuthLog::DocAuthFunnelSummaryStats.new.call
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/gpo_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class GpoReport < BaseReport
REPORT_NAME = 'usps-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(today)
@results = {
today: today.to_s,
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/monthly_gpo_letter_requests_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class MonthlyGpoLetterRequestsReport < BaseReport
REPORT_NAME = 'monthly-usps-letter-requests-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date, start_time: first_of_this_month, end_time: end_of_today)
daily_results = transaction_with_timeout do
::LetterRequestsToGpoFtpLog.where(ftp_at: start_time..end_time)
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/omb_fitara_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ class OmbFitaraReport < BaseReport
MOST_RECENT_MONTHS_COUNT = 2
REPORT_NAME = 'omb-fitara-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
results = transaction_with_timeout do
report_hash
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/proofing_costs_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class ProofingCostsReport < BaseReport
REPORT_NAME = 'proofing-costs-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
report = transaction_with_timeout do
Db::ProofingCost::ProofingCostsSummary.new.call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class SpActiveUsersOverPeriodOfPerformanceReport < BaseReport
REPORT_NAME = 'sp-active-users-over-period-of-performance-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
results = transaction_with_timeout do
Db::Identity::SpActiveUserCountsWithinIaaWindow.call
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/sp_active_users_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class SpActiveUsersReport < BaseReport
REPORT_NAME = 'sp-active-users-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

# This daily job captures the total number of active users per SP from the beginning of the the
# current fiscal year until now.
#
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/sp_cost_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class SpCostReport < BaseReport
REPORT_NAME = 'sp-cost-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
results = transaction_with_timeout do
Db::SpCost::SpCostSummary.call(first_of_this_month, end_of_today)
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/sp_user_counts_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class SpUserCountsReport < BaseReport
REPORT_NAME = 'sp-user-counts-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
user_counts = transaction_with_timeout do
Db::Identity::SpUserCounts.call
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/sp_user_quotas_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class SpUserQuotasReport < BaseReport
REPORT_NAME = 'sp-user-quotas-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
results = run_report_and_save_to_s3
update_quota_limit_cache
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/total_ial2_costs_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class TotalIal2CostsReport < BaseReport
REPORT_NAME = 'total-ial2-costs'.freeze
NUM_LOOKBACK_DAYS = 45

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(date)
results = transaction_with_timeout { query(date) }

Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/total_monthly_auths_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class TotalMonthlyAuthsReport < BaseReport
REPORT_NAME = 'total-monthly-auths-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
auth_counts = transaction_with_timeout do
Db::MonthlySpAuthCount::TotalMonthlyAuthCounts.call
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/reports/total_sp_cost_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Reports
class TotalSpCostReport < BaseReport
REPORT_NAME = 'total-sp-cost-report'.freeze

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
total_limit: 1,
key: -> { "#{REPORT_NAME}-#{arguments.first}" },
)

def perform(_date)
auth_counts = transaction_with_timeout do
Db::SpCost::TotalSpCostSummary.call(first_of_this_month, end_of_today)
Expand Down
Loading