-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move file related listeners to their own space (#6743)
* move file related listeners to their own space these listener methods don't have to do with `FileMetadata`, so they should be reorganized out into their own class. this makes it easier for downstream apps to override behaviors that are only related to files. * fix typo "Listener" -> "Listeners" --------- Co-authored-by: tamsin woo <[email protected]>
- Loading branch information
tamsin woo
and
tamsin woo
authored
Mar 28, 2024
1 parent
27499ad
commit b1789c0
Showing
3 changed files
with
50 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyrax | ||
module Listeners | ||
## | ||
# Listens for events related to Files ({Valkyrie::StorageAdapter::File}) | ||
class FileListener | ||
## | ||
# Called when 'file.characterized' event is published; | ||
# allows post-characterization handling, like derivatives generation. | ||
# | ||
# @param [Dry::Events::Event] event | ||
# @return [void] | ||
def on_file_characterized(event) | ||
file_set = event[:file_set] | ||
|
||
case file_set | ||
when ActiveFedora::Base # ActiveFedora | ||
CreateDerivativesJob | ||
.perform_later(file_set, event[:file_id], event[:path_hint]) | ||
else | ||
ValkyrieCreateDerivativesJob | ||
.perform_later(file_set.id.to_s, event[:file_id]) | ||
end | ||
end | ||
|
||
## | ||
# Called when 'file.uploaded' event is published | ||
# @param [Dry::Events::Event] event | ||
# @return [void] | ||
def on_file_uploaded(event) | ||
# Run characterization for original file only | ||
return unless event[:metadata]&.original_file? | ||
|
||
ValkyrieCharacterizationJob.perform_later(event[:metadata].id.to_s) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters