Redirect dead bookmarks to archive.org

This commit is contained in:
2023-11-18 14:31:03 +11:00
parent fae1fc092e
commit 9d6beadcd9
3 changed files with 5 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ require "que"
module Adamantium module Adamantium
module Jobs module Jobs
class RemoveDeadBookmarks < Que::Job class ArchiveDeadBookmarks < Que::Job
def run def run
bookmark_repo = Admin::Container["repos.bookmark_repo"] bookmark_repo = Admin::Container["repos.bookmark_repo"]
@@ -12,7 +12,7 @@ module Adamantium
bookmarks.each do |bookmark| bookmarks.each do |bookmark|
code = HTTParty.get(bookmark.url, follow_redirects: false).code code = HTTParty.get(bookmark.url, follow_redirects: false).code
if code >= 400 if code >= 400
bookmark_repo.archive(id: bookmark.id) bookmark_repo.update(bookmark.id, {url: "https://web.archive.org/web/*/#{bookmark.url}"})
end end
end end
end end

View File

@@ -8,10 +8,10 @@ module Admin
Que.connection = Adamantium::Container["persistence.db"] Que.connection = Adamantium::Container["persistence.db"]
res.status = 200 res.status = 200
if Que.job_stats.any? { |job| job[:job_class] == Adamantium::Jobs::RemoveDeadBookmarks.name } if Que.job_stats.any? { |job| job[:job_class] == Adamantium::Jobs::ArchiveDeadBookmarks.name }
res.body = "Job already queued" res.body = "Job already queued"
else else
Adamantium::Jobs::RemoveDeadBookmarks.enqueue Adamantium::Jobs::ArchiveDeadBookmarks.enqueue
res.body = "#{Que.job_stats.count} job queued" res.body = "#{Que.job_stats.count} job queued"
end end
end end

View File

@@ -20,7 +20,7 @@ module Admin
expose :running_jobs do expose :running_jobs do
Que.connection = Adamantium::Container["persistence.db"] Que.connection = Adamantium::Container["persistence.db"]
Que.job_stats.any? { |job| job[:job_class] == Adamantium::Jobs::RemoveDeadBookmarks.name } Que.job_stats.any? { |job| job[:job_class] == Adamantium::Jobs::ArchiveDeadBookmarks.name }
end end
end end
end end