diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-07-29 14:26:41 -0500 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-07-29 14:26:41 -0500 |
commit | 74290d4eb3f6771ad21d9e2c1d0a76d4f76bb263 (patch) | |
tree | a6309badafe748d3a0269d23a00411c8586299d3 /app/workers | |
parent | 02729ab3ae3f5a59b6c9b84bd24282e9a003e3d2 (diff) |
optional delayed publishing of roars for proofreading
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/distribution_worker.rb | 4 | ||||
-rw-r--r-- | app/workers/post_status_worker.rb | 43 |
2 files changed, 45 insertions, 2 deletions
diff --git a/app/workers/distribution_worker.rb b/app/workers/distribution_worker.rb index 4e20ef31b..0775e30e6 100644 --- a/app/workers/distribution_worker.rb +++ b/app/workers/distribution_worker.rb @@ -3,10 +3,10 @@ class DistributionWorker include Sidekiq::Worker - def perform(status_id) + def perform(status_id, delayed = false) RedisLock.acquire(redis: Redis.current, key: "distribute:#{status_id}") do |lock| if lock.acquired? - FanOutOnWriteService.new.call(Status.find(status_id)) + FanOutOnWriteService.new.call(Status.find(status_id), delayed) else raise Mastodon::RaceConditionError end diff --git a/app/workers/post_status_worker.rb b/app/workers/post_status_worker.rb new file mode 100644 index 000000000..e9b73b8bc --- /dev/null +++ b/app/workers/post_status_worker.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +class PostStatusWorker + include Sidekiq::Worker + + sidekiq_options unique: :until_executed + + def perform(status_id, options = {}) + status = Status.find(status_id) + return false if status.destroyed? + + if options[:visibility] + status.visibility = options[:visibility] + status.save! + end + + process_mentions_service.call(status) unless options[:nomentions] + + LinkCrawlWorker.perform_async(status.id) unless options[:nocrawl] || status.spoiler_text? + DistributionWorker.perform_async(status.id) unless options[:distribute] == false + + unless status.local_only? || options[:distribute] == false || options[:federate] == false + ActivityPub::DistributionWorker.perform_async(status.id) + end + + PollExpirationNotifyWorker.perform_at(status.poll.expires_at, status.poll.id) if status.poll + + status.delete_after = options[:delete_after] if options[:delete_after] + + return true if !status.reply? || status.account.id == status.in_reply_to_account_id + ActivityTracker.increment('activity:interactions') + return if status.account.following?(status.in_reply_to_account_id) + PotentialFriendshipTracker.record(status.account.id, status.in_reply_to_account_id, :reply) + + true + rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid + true + end + + def process_mentions_service + ProcessMentionsService.new + end +end |