Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Halt ingestion when WordPress Photo Directory reaches last page #916

Merged
merged 7 commits into from
Dec 13, 2022

Conversation

stacimc
Copy link
Contributor

@stacimc stacimc commented Dec 10, 2022

Fixes

Fixes WordPress/openverse#1372 by @AetherUnbound

Description

The WordPress Photo Directory DAG was failing to halt ingestion gracefully when it reached the end of its data. Instead, it raises a 400 when attempting to access a page number beyond the total page count. This is especially bad if skip_ingestion_errors is enabled, because it will retry infinitely.

To fix this we need to make a HEAD request to get the total page count. This information is only available in the headers and not response_json, so we are not able to fetch it in get_batch_data. This PR makes this additional request on the first batch, and then halts ingestion during get_should_continue when we reach the final page.

Testing Instructions

At the time this PR was written, this DAG detects 53 pages of results. To test it locally, I recommend editing the initial current_page variable in the __init__ method to 52, so the DAG will run quickly and hit the last page:

def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        <...>

        self.current_page = 52

After making the edit, run the DAG and verify that it stops gracefully when the last page has been reached. You should be able to see a log that looks like:

The final page of data has been processed. Halting ingestion.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@stacimc stacimc added bug Something isn't working 🟧 priority: high Stalls work on the project or its dependents 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository labels Dec 10, 2022
@stacimc stacimc requested a review from a team as a code owner December 10, 2022 02:13
@stacimc stacimc self-assigned this Dec 10, 2022
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

This LGTM and tests fine locally. Thank you for the good instructions.

I was wondering if you had considered any alternative solutions to this, perhaps ones that would add the ability to get the headers to the base class? I had one idea for how to do it so that it would always be available as part of response_json but didn't want to get into it if you thought it was a YAGNI type situation.

Anyway, LGTM either way and the solution makes sense for this DAG.

Copy link
Member

@krysal krysal left a comment

Choose a reason for hiding this comment

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

Nice! I was thinking about the general solution for the response headers as well but that seemed to require much refactorization of other DAGs for just using it here. I like this.

Good code coverage in testing too! It's appreciated.

@sarayourfriend
Copy link
Contributor

I have at least one idea that wouldn't require any refactors of other DAGs, but would be a little obscure: subclass dict and add a headers attribute. Then map the JSON response into the dict subclass and add the headers to the headers attribute.

@stacimc
Copy link
Contributor Author

stacimc commented Dec 12, 2022

I was wondering if you had considered any alternative solutions to this, perhaps ones that would add the ability to get the headers to the base class?

We definitely can, but I wasn't aware of any other cases where we needed it (although I could be wrong). I'd say I have a slight preference to refactoring more fully if/when another use case arises... although the dict subclassing idea is pretty slick @sarayourfriend 🤩

@sarayourfriend
Copy link
Contributor

I'd say I have a slight preference to refactoring more fully if/when another use case arises

I like this as well 🚀

@stacimc stacimc merged commit 5933f71 into main Dec 13, 2022
@stacimc stacimc deleted the fix/wordpress-photo-directory-stop-ingestion branch December 13, 2022 18:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository bug Something isn't working 🛠 goal: fix Bug fix 🟧 priority: high Stalls work on the project or its dependents
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WordPress Photo Directory provider script does not stop
4 participants