Repository navigation
feat(ingest): accept uploads and queue them as jobs #437
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac718b0
feat(ingest): accept uploads and queue them as jobs
lewismc 358fdae
feat(ingest): queue large uploads outside the request
lewismc 7257b0d
fix: clear the Sonar reliability findings on ingest uploads
lewismc 79813ab
fix: keep the staging watcher moving through every dropped file
lewismc 3946ff1
fix: wait for both staging jobs to be recorded as pending
lewismc a48c088
Merge branch 'main' into feat/async-ingest
lewismc 92516ef
Merge branch 'main' into feat/async-ingest
lewismc fb5c3f9
Merge branch 'main' into feat/async-ingest
lewismc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| */1 * * * * tagbase . /usr/src/app/.env && /usr/local/bin/python3 /usr/src/app/poll_metadata_and_obs_types.py >/proc/1/fd/1 2>/proc/1/fd/2 | ||
| 15 3 * * * tagbase . /usr/src/app/.env && /usr/local/bin/python3 /usr/src/app/purge_ingest_jobs.py >/proc/1/fd/1 2>/proc/1/fd/2 |
This file contains hidden or 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 hidden or 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,53 @@ | ||
| #!/usr/bin/env python3 | ||
| """Delete terminal ingest_job rows older than the retention window.""" | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| import psycopg2 | ||
|
|
||
| DEFAULT_RETENTION_DAYS = 30 | ||
|
|
||
|
|
||
| def retention_days(): | ||
| raw = os.getenv("INGEST_JOB_RETENTION_DAYS", str(DEFAULT_RETENTION_DAYS)) | ||
| return int(raw) | ||
|
|
||
|
|
||
| def connect(): | ||
| try: | ||
| return psycopg2.connect( | ||
| dbname="tagbase", | ||
| user="tagbase", | ||
| host="postgis", | ||
| port=os.getenv("POSTGRES_PORT", "5432"), | ||
| password=os.getenv("POSTGRES_PASSWORD", "tagbase"), | ||
| ) | ||
| except psycopg2.OperationalError as error: | ||
| print("Error connecting to DB: ", error) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def purge(connection, days): | ||
| with connection.cursor() as cursor: | ||
| cursor.execute( | ||
| """ | ||
| DELETE FROM ingest_job | ||
| WHERE status IN ('succeeded', 'failed') | ||
| AND updated_at < now() - (%s * interval '1 day') | ||
| """, | ||
| (days,), | ||
| ) | ||
| deleted = cursor.rowcount | ||
| connection.commit() | ||
| return deleted | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| window = retention_days() | ||
| conn = connect() | ||
| try: | ||
| removed = purge(conn, window) | ||
| finally: | ||
| conn.close() | ||
| print(f"Purged {removed} ingest_job row(s) older than {window} day(s)") |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will have to change this name in the future as well 😅 as per classic REST API design we should use nouns for resources , so we would have something
jobswith its own POST/GET/LIST and if we wanted to make it async, we could have a parameter for it?sync=trueor having/ingestions/sync+/ingestions/async, but we can also do that in a follow upThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we are going back to my previous comments. I agree with you. You and I know there are a lot of implicit implications with this design decision. I am +1. Lets do it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed as #469.