Skip to content

Commit

Permalink
Add box_destroyed event
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Sep 19, 2023
1 parent 63d7467 commit 28ae0e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions app/jobs/govbox/destroy_box_data_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Govbox
class DestroyBoxDataJob < ApplicationJob
queue_as :default

def perform(box)
Govbox::ApiConnection.find_by(box_id: box.id).destroy
Govbox::Folder.where(box_id: box.id).destroy_all
end
end
end
1 change: 1 addition & 0 deletions app/lib/event_bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ def self.reset!
->(message_thread_tag) { Searchable::ReindexMessageThreadJob.perform_later(message_thread_tag.message_thread) }
EventBus.subscribe :tag_renamed, ->(tag) { Searchable::ReindexMessageThreadsWithTagIdJob.perform_later(tag.id) }
EventBus.subscribe :tag_removed, ->(tag) { Searchable::ReindexMessageThreadsWithTagIdJob.perform_later(tag.id) }
EventBus.subscribe :box_destroyed, ->(box) { Govbox::DestroyBoxDataJob.perform_now(box) }
5 changes: 1 addition & 4 deletions app/models/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class Box < ApplicationRecord
has_many :message_threads, through: :folders, extend: MessageThreadsExtensions, dependent: :destroy
has_many :message_drafts_imports, dependent: :destroy

before_destroy do
Govbox::ApiConnection.find_by(box_id: id).destroy
Govbox::Folder.where(box_id: id).destroy_all
end
before_destroy ->(box) { EventBus.publish(:box_destroyed, box) }
end

0 comments on commit 28ae0e7

Please sign in to comment.