Unverified Commit 57c03305 authored by Benjamin Neff's avatar Benjamin Neff Committed by Dennis Schubert
Browse files

Schedule a connection-check when receiving a message from an offline pod

closes #7158
parent 08282cea
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -61,6 +61,10 @@ class Pod < ActiveRecord::Base
    def check_all!
      Pod.find_in_batches(batch_size: 20) {|batch| batch.each(&:test_connection!) }
    end

    def check_scheduled!
      Pod.where(scheduled_check: true).find_each(&:test_connection!)
    end
  end

  def offline?
@@ -76,6 +80,10 @@ class Pod < ActiveRecord::Base
    "#{id}:#{host}"
  end

  def schedule_check_if_needed
    update_column(:scheduled_check, true) if offline? && !scheduled_check
  end

  def test_connection!
    result = ConnectionTester.check uri.to_s
    logger.debug "tested pod: '#{uri}' - #{result.inspect}"
@@ -108,6 +116,7 @@ class Pod < ActiveRecord::Base

    attributes_from_result(result)
    touch(:checked_at)
    self.scheduled_check = false

    save
  end
+9 −0
Original line number Diff line number Diff line
module Workers
  class RecheckScheduledPods < Base
    sidekiq_options queue: :low

    def perform
      Pod.check_scheduled!
    end
  end
end
+3 −1
Original line number Diff line number Diff line
@@ -93,7 +93,9 @@ DiasporaFederation.configure do |config|
      end
    end

    on :receive_entity do |entity, _sender, recipient_id|
    on :receive_entity do |entity, sender, recipient_id|
      Person.by_account_identifier(sender).pod.try(:schedule_check_if_needed)

      case entity
      when DiasporaFederation::Entities::AccountDeletion
        Diaspora::Federation::Receive.account_deletion(entity)
+4 −0
Original line number Diff line number Diff line
@@ -9,3 +9,7 @@ queue_users_for_removal:
recurring_pod_check:
  cron: "0 0 * * *"
  class: "Workers::RecurringPodCheck"

recheck_scheduled_pods:
  cron: "*/30 * * * *"
  class: "Workers::RecheckScheduledPods"
+5 −0
Original line number Diff line number Diff line
class AddScheduledCheckToPod < ActiveRecord::Migration
  def change
    add_column :pods, :scheduled_check, :boolean, default: false, null: false
  end
end
Loading