migrate e621 jobs to unified domain models

This commit is contained in:
Dylan Knutson
2025-02-12 18:35:40 +00:00
parent 9c38bfce13
commit 8fc32e64e9
44 changed files with 940 additions and 422 deletions

View File

@@ -110,6 +110,7 @@ end
task infer_last_submission_log_entries: :environment do
only_fa_id = ENV["only_fa_id"]
start = ENV["start_at"]&.to_i || nil
if only_fa_id
relation = Domain::Fa::Post.where(fa_id: only_fa_id)
@@ -121,33 +122,43 @@ task infer_last_submission_log_entries: :environment do
.or(Domain::Fa::Post.where(state: :ok).where(posted_at: nil))
end
relation.find_each do |post|
relation.find_each(batch_size: 10, start:) do |post|
parts = ["[id: #{post.id}]", "[fa_id: #{post.fa_id}]"]
log_entry = post.guess_last_submission_page
if log_entry
contents = log_entry.response&.contents
if contents
parser = Domain::Fa::Parser::Page.new(contents)
if parser.submission_not_found?
parts << "[removed]"
post.state = :removed
else
posted_at = parser.submission.posted_date
parts << "[posted_at_parser: #{posted_at}]" if posted_at
end
end
if post.last_submission_page_id.present? &&
log_entry.id != post.last_submission_page_id
parts << "[overwrite]"
end
post.last_submission_page_id = log_entry.id
posted_at = post.posted_at ||= post.guess_posted_at
parts << "[posted_at_attr: #{posted_at}]" if posted_at
parts << "[submission log entry: #{log_entry.id}]"
parts << "[uri: #{log_entry.uri.to_s}]"
puts parts.join(" ")
post.save!
log_entry = post.guess_last_submission_page
unless log_entry
parts << "[no log entry]"
next
end
contents = log_entry.response&.contents
unless contents
parts << "[no contents]"
next
end
parser = Domain::Fa::Parser::Page.new(contents)
if parser.submission_not_found?
parts << "[removed]"
post.state = :removed
else
posted_at = parser.submission.posted_date
post.posted_at ||= posted_at
parts << "[posted at: #{posted_at}]"
end
if post.last_submission_page_id.present? &&
log_entry.id != post.last_submission_page_id
parts << "[overwrite]"
end
post.last_submission_page_id = log_entry.id
parts << "[log entry: #{log_entry.id}]"
parts << "[uri: #{log_entry.uri.to_s}]"
post.save!
rescue => e
parts << "[error: #{e.message}]"
ensure
puts parts.join(" ")
end
end