fix where ib file can get an md5 after first scan
This commit is contained in:
@@ -174,19 +174,35 @@ class Domain::Inkbunny::Job::UpdatePostsJob < Domain::Inkbunny::Job::Base
|
||||
logger.error("file has no md5") if md5_initial.blank?
|
||||
|
||||
file = post_files_by_ib_id[ib_file_id]
|
||||
if file.present? && (file.md5_initial != md5_initial)
|
||||
if file.present? && file.md5_initial.present? &&
|
||||
(file.md5_initial != md5_initial)
|
||||
fatal_error(
|
||||
"md5_initial changed #{file.md5_initial} -> #{md5_initial}",
|
||||
format_tags(
|
||||
make_tag("old md5", file.md5_initial),
|
||||
make_tag("new md5", md5_initial),
|
||||
"md5_initial changed",
|
||||
),
|
||||
)
|
||||
elsif file.present?
|
||||
logger.info("file already exists, skipping")
|
||||
elsif file.present? && file.md5_initial.present?
|
||||
logger.info(format_tags("file already exists, skipping"))
|
||||
next
|
||||
elsif file.present? && file.md5_initial.blank? && md5_initial.present?
|
||||
logger.warn(
|
||||
format_tags(
|
||||
make_tag("md5", md5_initial),
|
||||
"file got its first (delayed) md5_initial",
|
||||
),
|
||||
)
|
||||
file.md5_initial = md5_initial
|
||||
file.state_ok!
|
||||
elsif file.present?
|
||||
fatal_error("invariant")
|
||||
end
|
||||
|
||||
# We create all files, even those with null MD5 sums (which also do not have
|
||||
# a valid download URL), so that post.files.count will be accurate and match
|
||||
# pagecount.
|
||||
file =
|
||||
file ||=
|
||||
post.files.create do |file|
|
||||
md5_initial.present? ? file.state_ok! : file.state_terminal_error!
|
||||
file.ib_id = ib_file_id
|
||||
@@ -207,7 +223,9 @@ class Domain::Inkbunny::Job::UpdatePostsJob < Domain::Inkbunny::Job::Base
|
||||
end
|
||||
|
||||
if file.state_terminal_error?
|
||||
logger.error "file is in terminal error state, skipping enqueue"
|
||||
logger.error(
|
||||
format_tags("file is in terminal error state, skipping enqueue"),
|
||||
)
|
||||
next
|
||||
end
|
||||
|
||||
@@ -215,7 +233,7 @@ class Domain::Inkbunny::Job::UpdatePostsJob < Domain::Inkbunny::Job::Base
|
||||
fatal_error "file is invalid: #{format_tags_arr(file.errors.full_messages)}"
|
||||
end
|
||||
|
||||
logger.info "created new file"
|
||||
logger.info format_tags("created new file")
|
||||
|
||||
defer_job(
|
||||
Domain::Inkbunny::Job::StaticFileJob,
|
||||
|
||||
@@ -123,6 +123,41 @@ describe Domain::Inkbunny::Job::UpdatePostsJob do
|
||||
)
|
||||
end
|
||||
|
||||
it "enqueues file jobs when file first gets an md5_initial" do
|
||||
file =
|
||||
post_3104202.files.create(
|
||||
ib_id: 4_652_537,
|
||||
state: "terminal_error",
|
||||
md5_initial: "",
|
||||
)
|
||||
file.save!
|
||||
|
||||
perform_now({ ib_post_ids: ib_post_ids, caused_by_entry: nil })
|
||||
|
||||
file.reload
|
||||
expect(file.md5_initial).to eq("fbeb553c483a346108beeada93d90086")
|
||||
expect(file.state).to eq("ok")
|
||||
expect(
|
||||
SpecUtil.enqueued_job_args(Domain::Inkbunny::Job::StaticFileJob),
|
||||
).to include({ file:, caused_by_entry: log_entries[0] })
|
||||
end
|
||||
|
||||
it "throws an error when the md5_initial changes" do
|
||||
file =
|
||||
post_3104202.files.create!(
|
||||
ib_id: 4_652_537,
|
||||
state: "ok",
|
||||
md5_initial: "12345",
|
||||
)
|
||||
|
||||
perform_now(
|
||||
{ ib_post_ids: ib_post_ids, caused_by_entry: nil },
|
||||
should_raise: /md5_initial changed/,
|
||||
)
|
||||
|
||||
expect(file.reload.md5_initial).to eq("12345")
|
||||
end
|
||||
|
||||
it "updates posts with detailed information" do
|
||||
perform_now({ ib_post_ids: ib_post_ids, caused_by_entry: nil })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user