Files
redux-scraper/app/jobs/job_helper.rb
Dylan Knutson 025b4ac8e4 Add JobHelper module and enhance Inkbunny job processing
- Introduced a new `JobHelper` module to encapsulate job retrieval and execution logic, enforcing strict typing with Sorbet.
- Updated `UpdatePostsJob` to improve logging and error handling for file processing, including handling files with null MD5 sums.
- Enhanced validation in `Domain::Inkbunny::File` model to conditionally require presence of certain attributes based on file state.
- Added a new fixture for testing scenarios involving submissions with null MD5 sums, improving test coverage and robustness.

These changes aim to improve type safety, maintainability, and error handling in job processing logic.
2025-01-02 17:52:11 +00:00

33 lines
966 B
Ruby

# typed: strict
module JobHelper
extend T::Sig
# @param good_job_uuid [String]
# @return [GoodJob::Job]
sig { params(good_job_uuid: String).returns(GoodJob::Job) }
def self.find_job(good_job_uuid)
GoodJob::Job.find(good_job_uuid)
end
# @param good_job_uuid [String]
# @return [void]
sig { params(good_job_uuid: String).void }
def self.perform_job(good_job_uuid)
job = find_job(good_job_uuid)
job_args_deserialized =
T.let(
ActiveJob::Arguments.deserialize(job.serialized_params),
T::Array[[String, T.untyped]],
)
job_args = job_args_deserialized.find { |key, _| key == "arguments" }
raise("no arguments for #{job.job_class}") if job_args.nil?
job_args = T.cast(job_args[1], T::Array[T.untyped])
job_instance =
job.job_class&.constantize&.new ||
raise("no job_class for #{job.job_class}")
job_instance.arguments = job_args
job_instance&.perform(*job_args)
end
end