Handle full content lifecycle for subscribed fasps

This commit is contained in:
David Roetzel 2024-12-16 15:50:59 +01:00
parent e234a89e06
commit 3f5c040d7c
No known key found for this signature in database
2 changed files with 39 additions and 1 deletions

View File

@ -5,12 +5,22 @@ module Status::FaspConcern
included do included do
after_commit :announce_new_content_to_subscribed_fasp, on: :create after_commit :announce_new_content_to_subscribed_fasp, on: :create
after_commit :announce_updated_content_to_subscribed_fasp, on: :update
after_commit :announce_deleted_content_to_subscribed_fasp, on: :destroy
end end
private private
def announce_new_content_to_subscribed_fasp def announce_new_content_to_subscribed_fasp
store_uri unless uri # TODO: solve this more elegantly store_uri unless uri # TODO: solve this more elegantly
Fasp::AnnounceNewContentWorker.perform_async(uri) Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'new')
end
def announce_updated_content_to_subscribed_fasp
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'update')
end
def announce_deleted_content_to_subscribed_fasp
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'delete')
end end
end end

View File

@ -0,0 +1,28 @@
# frozen_string_literal: true
class Fasp::AnnounceContentLifecycleEventWorker
include Sidekiq::Worker
sidekiq_options queue: 'fasp', retry: 5
def perform(uri, event_type)
Fasp::Subscription.includes(:fasp_provider).content.lifecycle.each do |subscription|
announce(subscription, uri, event_type)
end
end
private
def announce(subscription, uri, event_type)
Fasp::Request.new(subscription.fasp_provider).post('/data_sharing/v0/announcements', body: {
source: {
subscription: {
id: subscription.id.to_s,
},
},
category: 'content',
eventType: event_type,
objectUris: [uri],
})
end
end