From d9715bf9ac16abe34f212548d0682e0d97e6d9d6 Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sun, 24 Sep 2023 15:23:39 +1000 Subject: [PATCH] Send web mentions in the background --- app/commands/posts/create_entry.rb | 4 ++-- app/commands/posts/send_webmentions.rb | 13 ++++--------- config/app.rb | 3 ++- lib/adamantium/jobs/send_web_mentions.rb | 23 +++++++++++++++++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 lib/adamantium/jobs/send_web_mentions.rb diff --git a/app/commands/posts/create_entry.rb b/app/commands/posts/create_entry.rb index 4169cd2..079987f 100644 --- a/app/commands/posts/create_entry.rb +++ b/app/commands/posts/create_entry.rb @@ -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 diff --git a/app/commands/posts/send_webmentions.rb b/app/commands/posts/send_webmentions.rb index 494a734..63ca890 100644 --- a/app/commands/posts/send_webmentions.rb +++ b/app/commands/posts/send_webmentions.rb @@ -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 diff --git a/config/app.rb b/config/app.rb index f03a96e..c54aba0 100644 --- a/config/app.rb +++ b/config/app.rb @@ -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 diff --git a/lib/adamantium/jobs/send_web_mentions.rb b/lib/adamantium/jobs/send_web_mentions.rb new file mode 100644 index 0000000..bbdfafc --- /dev/null +++ b/lib/adamantium/jobs/send_web_mentions.rb @@ -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