Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎁 Add graceful fallback of preprocessing #283

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

jeremyf
Copy link
Contributor

@jeremyf jeremyf commented Nov 6, 2023

Prior to this commit, if we did not actually have preprocessed file in
the remote system, we'd encounter errors with files missing; we assumed
we could "copy" the preprocessed url to the local file.

With this commit, we check to see if the preprocessed file exists. Then
fallback to a specified FileSet#remote_url and the fallback even
further.

The specs define the expected behavior.

Closes #282

Related to:

Prior to this commit, if we did not actually have preprocessed file in
the remote system, we'd encounter errors with files missing; we assumed
we could "copy" the preprocessed url to the local file.

With this commit, we check to see if the preprocessed file exists.  Then
fallback to a specified FileSet#remote_url and the fallback even
further.

The specs define the expected behavior.

Closes #282

Related to:

- #282

@preprocessed_location_template =
if rodeo_conformant_uri_exists?(derivative_rodeo_candidate)
Rails.logger.debug("#{self.class}##{__method__} found existing file at location #{derivative_rodeo_candidate}. High five partner!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah!

@jeremyf jeremyf merged commit 5fb1531 into main Nov 6, 2023
9 of 10 checks passed
@jeremyf jeremyf deleted the i282-gracefully-handling-of-copy-failure branch November 6, 2023 20:34
jeremyf added a commit to notch8/derivative_rodeo that referenced this pull request Nov 8, 2023
In working towards gracefully handling a failed copy of a resource in
SpaceStone, we conditionally updated the `preprocess_template_location` to
be the original HTTP(s) location.  The idea being that if it does not
exist in the pre-processed location

The
[DerivativeRodeo::Generators::PdfSplitGenerator](https://github.com/scientist-softserv/derivative_rodeo/blob/84aa08e8387f105488a2b1a1e3821abacff4ad64/lib/derivative_rodeo/generators/pdf_split_generator.rb#L70-L80)
method (see below) can gracefully handle returning an empty list of
output locations.

```ruby
def existing_page_locations(input_location:)
  # See image_file_basename_template
  tail_regexp = %r{#{input_location.file_basename}--page-\d+\.#{output_extension}$}

  output_locations = input_location.derived_file_from(template: output_location_template).matching_locations_in_file_dir(tail_regexp: tail_regexp)
  return output_locations if output_locations.count.positive?

  return [] if preprocessed_location_template.blank?

  input_location.derived_file_from(template: preprocessed_location_template).matching_locations_in_file_dir(tail_regexp: tail_regexp)
end
```

At issue is understanding if we need to use the copy task to copy the
file locally.  We shall see once this is in play.

Related to:

- notch8/iiif_print#283
- #71
jeremyf added a commit that referenced this pull request Nov 8, 2023
We need to address the case where SpaceStone failed to copy the file
into S3.  When the file does not exist in S3, we can check if we have
the file locally and use that as the pre-processed location.  Otherwise,
we can copy the original remote file and proceed.

Related to:

- #283
- #282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Graceful handling of derivative rodeo preprocessed file missing
2 participants