discourse/app/jobs/regular/run_problem_check.rb
Jarek Radosz b28fafd372
DEV: Fix job serialization warnings (#30735)
(…and remove extraneous `stringify_keys` - enqueue already does
`deep_stringify_keys`)

The warning in question:

```
Deprecation notice: Jobs::RunProblemCheck was enqueued with argument values which do not cleanly serialize to/from JSON. This means that the job will be run with slightly different values than the ones supplied to `enqueue`. Argument values should be strings, booleans, numbers, or nil (or arrays/hashes of those value types). (deprecated since Discourse 2.9) (removal in Discourse 3.0)
```
2025-01-13 13:35:40 +01:00

35 lines
900 B
Ruby

# frozen_string_literal: true
module Jobs
class RetrySignal < Exception
end
# This job runs a singular scheduled admin check. It is scheduled by
# the ProblemChecks (plural) scheduled job.
class RunProblemCheck < ::Jobs::Base
sidekiq_options retry: false
def execute(args)
retry_count = args[:retry_count].to_i
identifier = args[:check_identifier].to_sym
check = ProblemCheck[identifier]
check.run do |problems|
raise RetrySignal if problems.present? && retry_count < check.max_retries
end
rescue RetrySignal
Jobs.enqueue_in(
check.retry_after,
:run_problem_check,
args.merge(retry_count: retry_count + 1),
)
rescue StandardError => err
Discourse.warn_exception(
err,
message: "A scheduled admin dashboard problem check (#{identifier}) errored.",
)
end
end
end