Send web mentions in the background

This commit is contained in:
2023-09-24 15:23:39 +10:00
parent a9aa16da8b
commit d9715bf9ac
4 changed files with 31 additions and 12 deletions

View File

@@ -23,9 +23,9 @@ module Adamantium
syndicate.call(created_post.id, post)
# decorated_post = Decorators::Posts::Decorator.new(created_post)
decorated_post = Decorators::Posts::Decorator.new(created_post)
# send_webmentions.call(post_content: attrs[:content], post_url: decorated_post.permalink)
send_webmentions.call(post_content: created_post.content, post_url: decorated_post.permalink)
Success(created_post)
end

View File

@@ -1,4 +1,5 @@
require "httparty"
require "que"
module Adamantium
module Commands
@@ -7,15 +8,9 @@ module Adamantium
include Deps["settings", "post_utilities.link_finder"]
def call(post_content:, post_url:)
source = post_url
links = link_finder.call(post_content)
links.each do |target|
HTTParty.post(settings.webmention_service, {
token: settings.webmention_token,
source: source,
target: target
})
end
Que.connection = Adamantium::Container["persistence.db"]
Adamantium::Jobs::SendWebMentions.enqueue(post_content: post_content, post_url: post_url)
end
end
end

View File

@@ -22,7 +22,8 @@ module Adamantium
config.shared_app_component_keys += [
"syndication.dayone",
"renderers.markdown"
"renderers.markdown",
"post_utilities.link_finder"
]
config.assets.manifest_path = Hanami.env == :production ? "public/assets/asset-manifest.json" : nil

View File

@@ -0,0 +1,23 @@
require "httparty"
require "que"
module Adamantium
module Jobs
class SendWebMentions < Que::Job
def run(post_content:, post_url:)
link_finder = Admin::Container["post_utilities.link_finder"]
settings = Admin::Container["settings"]
source = post_url
links = link_finder.call(post_content)
links.each do |target|
HTTParty.post(settings.webmention_service, {
token: settings.webmention_token,
source: source,
target: target
})
end
end
end
end
end