Skip to content

Commit

Permalink
Merge pull request #526 from NASA-IMPACT/525-pull-github-metadata-usi…
Browse files Browse the repository at this point in the history
…ng-celery-instead-of-in-the-request

Use celery to pull latest collection metadata from github
  • Loading branch information
code-geek authored Nov 27, 2023
2 parents 1e21574 + de9d753 commit 66f9e1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions sde_collections/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,11 @@ def push_to_github_task(collection_ids):
def sync_with_production_webapp():
for collection in Collection.objects.all():
collection.sync_with_production_webapp()


@celery_app.task()
def pull_latest_collection_metadata_from_github(collection_ids):
FILENAME = "github_collections.json"
gh = GitHubHandler(collections=Collection.objects.none())
collections = gh.get_collections_from_github()
json.dump(collections, open(FILENAME, "w"), indent=4)
10 changes: 5 additions & 5 deletions sde_collections/utils/health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
DocumentTypes,
)
from sde_collections.models.pattern import ExcludePattern, TitlePattern
from sde_collections.tasks import _get_data_to_import
from sde_collections.utils.github_helper import GitHubHandler
from sde_collections.tasks import (
_get_data_to_import,
pull_latest_collection_metadata_from_github,
)


def health_check(collection, server_name: str = "production") -> dict:
Expand Down Expand Up @@ -223,9 +225,7 @@ def generate_db_github_metadata_differences(reindex_configs_from_github=False):
if os.path.exists(FILENAME) and not reindex_configs_from_github:
collections = json.load(open(FILENAME))
else:
gh = GitHubHandler(collections=Collection.objects.none())
collections = gh.get_collections_from_github()
json.dump(collections, open(FILENAME, "w"), indent=4)
pull_latest_collection_metadata_from_github.delay()

# also fetch same metadata from the database
for collection in collections:
Expand Down

0 comments on commit 66f9e1b

Please sign in to comment.