# app/jobs/training_watch_job.rb class TrainingWatchJob < ApplicationJob queue_as :training_watch include GoodJob::ActiveJobExtensions::Concurrency good_job_control_concurrency_with( # Maximum number of unfinished jobs to allow with the concurrency key total_limit: 1, # Or, if more control is needed: # Maximum number of jobs with the concurrency key to be # concurrently enqueued (excludes performing jobs) enqueue_limit: 1, # Maximum number of jobs with the concurrency key to be # concurrently performed (excludes enqueued jobs) perform_limit: 1, # Note: Under heavy load, the total number of jobs may exceed the # sum of `enqueue_limit` and `perform_limit` because of race conditions # caused by imperfectly disjunctive states. If you need to constrain # the total number of jobs, use `total_limit` instead. See #378. # A unique key to be globally locked against. # Can be String or Lambda/Proc that is invoked in the context of the job. # Note: Arguments passed to #perform_later must be accessed through `arguments` method. key: -> { "Unique-TrainingWatchJob" } ) def perform results = TrainingWatch::Checker.new.run! return if results.empty? email = ENV.fetch("TRAINING_WATCH_NOTIFY_EMAIL", "christoph@marzell.net") return if email.blank? TrainingWatchMailer.notify(email: email, results: results).deliver_now end end