From 8a279a3f12cb9a6884747e313497a24f1155d8e3 Mon Sep 17 00:00:00 2001 From: Simon Liu <69875423+sliu008@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:32:36 -0800 Subject: [PATCH] Feature/first implementation (#1) * fix pylint * more initial testing * temp tests * test * testing * update print messages on what collection is being sync * fix umm v auto sync conflicts * update cron to run at midnight pst --- .github/workflows/main.yml | 18 +++++++++++++++--- umm_v_auto/podaac/umm_v_auto_sync.py | 19 ++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7d79263..c259f08 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ name: Umm V Auto Sync # Controls when the workflow will run on: schedule: - - cron: '0 0 * * *' # Set the cron schedule for nightly build (UTC time) + - cron: '0 8 * * *' # Set the cron schedule for midnight PST branches: - main workflow_dispatch: @@ -13,7 +13,7 @@ on: jobs: # First job in the workflow installs and verifies the software build: - name: Build, Test, Verify, Publish + name: Build, Test # The type of runner that the job will run on runs-on: ubuntu-latest steps: @@ -37,9 +37,21 @@ jobs: ######################################################################### # NOTE: This step is platform-specific # These are gradle-specific steps for installing the application + - name: Poetry Steps - name: Install Software working-directory: umm_v_auto run: | poetry install poetry run pylint podaac - poetry run flake8 podaac \ No newline at end of file + poetry run flake8 podaac + + ######################################################################### + # UMM V Auto Sync + ######################################################################### + - name: UMM V Auto Sync + working-directory: umm_v_auto + env: + UAT_TOKEN_TEMP: ${{ secrets.LAUNCHPAD_TOKEN_UAT }} + OPS_TOKEN_TEMP: ${{ secrets.LAUNCHPAD_TOKEN_OPS }} + run: | + poetry run python podaac/umm_v_auto_sync.py -ut $UAT_TOKEN_TEMP -ot $OPS_TOKEN_TEMP diff --git a/umm_v_auto/podaac/umm_v_auto_sync.py b/umm_v_auto/podaac/umm_v_auto_sync.py index 95c6a77..5f78c46 100644 --- a/umm_v_auto/podaac/umm_v_auto_sync.py +++ b/umm_v_auto/podaac/umm_v_auto_sync.py @@ -24,12 +24,12 @@ def search_source(search_api: str, concept_id: str, **kwargs) -> dict: try: source_coll_meta = search( f"{search_api}/collections.umm_json", params=source_coll_params).get("items")[0] - except (KeyError, IndexError) as e: # pylint: disable = unused-variable + except (KeyError, IndexError) as e: # noqa: F841 pylint: disable = unused-variable raise Exception( - f"ERROR! Source collection was not found in CMR ({source_cmr}) for the input concept-id ({source_coll})") - except JSONDecodeError as e: + f"ERROR! Source collection was not found in CMR ({source_cmr}) for the input concept-id ({source_coll})") # noqa: F821 + except json.JSONDecodeError as e: # noqa: F841 raise Exception( - f"ERROR! Source collection metadata could not be accessed from CMR ({source_cmr}) due to http request failure") + f"ERROR! Source collection metadata could not be accessed from CMR ({source_cmr}) due to http request failure") # noqa: F821 if 'associations' in source_coll_meta.get("meta"): if 'variables' in source_coll_meta.get("meta").get("associations"): @@ -72,7 +72,7 @@ def _ingest(record_data: dict) -> dict: 'Accept': "application/json", }).json() ummvar_concept_id = response.get("concept-id") - except json.JSONDecodeError as e: # pylint: disable = unused-variable + except json.JSONDecodeError as e: # # noqa: F841 pylint: disable = unused-variable print( f"ERROR! {ummvar_native_id} -- TODO: Handle failed requests w/ logic to retry errors that appear transient.") except Exception as e: # Skip exceptions so the previous api repsonses are retained. @@ -105,12 +105,12 @@ def parse_args(): parser.add_argument('-ut', '--uat_token', help='launchpad token file for uat', - required=False, + required=True, metavar='') parser.add_argument('-ot', '--ops_token', help='launchpad token file for ops', - required=False, + required=True, metavar='') args = parser.parse_args() @@ -130,7 +130,7 @@ def get_ops_collection_concept_id(env, collection_name, headers): collections_query = requests.get(url, headers=headers, params={ 'page_size': 2000}).json()['feed']['entry'] - if collection_name not in ops_collection_name_id: + if collection_name not in ops_collection_name_id and len(collections_query) > 0: variables = collections_query[0].get( "associations").get("variables", []) @@ -251,4 +251,5 @@ def sync_ops_umm_v_to_uat(ops_concept_id, ops_token, uat_token): if uat_umm_v == 0: ops_concept_id = ops_collection_name_id[collection].get( 'concept_id') - sync_ops_umm_v_to_uat(ops_concept_id, _args.ops_token, _args.uat_token) + print(f"Sync collection {collection}") + sync_ops_umm_v_to_uat(ops_concept_id, _args.ops_token, _args.uat_token) \ No newline at end of file