Skip to content

Commit

Permalink
Merge pull request #156 from wri/develop
Browse files Browse the repository at this point in the history
Batman fixes to master
  • Loading branch information
jterry64 authored Sep 17, 2024
2 parents e5c5fc8 + ba465d2 commit 1f53010
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/datapump/clients/data_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,24 @@ def create_vector_version(
def create_version(
self, dataset: str, version: str, payload: Dict[str, Any]
) -> Dict[str, Any]:

uri = f"{GLOBALS.data_api_uri}/dataset/{dataset}/{version}"
return self._send_request(ValidMethods.put, uri, payload)["data"]
try:
uri = f"{GLOBALS.data_api_uri}/dataset/{dataset}/{version}"
return self._send_request(ValidMethods.put, uri, payload)["data"]
except DataApiResponseError as e:
# Workaround for GTC-2986
# Getting a 500 response when creating version, but version is still created
# causing a 400 response on subsequent retries since we're trying to PUT
# an already existing version.
# For now, let's just return the version if it exists.
# Otherwise, propagate original exception.
try:
return self.get_version(dataset, version)
except DataApiResponseError:
raise e

def create_aux_asset(
self, dataset: str, version: str, payload: Dict[str, Any]
) -> Dict[str, Any]:

uri = f"{GLOBALS.data_api_uri}/dataset/{dataset}/{version}/assets"
return self._send_request(ValidMethods.post, uri, payload)["data"]

Expand Down
7 changes: 5 additions & 2 deletions src/datapump/sync/rw_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import traceback
from contextlib import contextmanager
from datetime import datetime, timedelta
from typing import Any, Dict, Iterator, List, Optional, Set, Tuple

import requests
Expand Down Expand Up @@ -82,8 +83,10 @@ def get_pending_areas() -> List[Any]:
LOGGER.info(f"Using token {token()} for {api_prefix()} API")
headers: Dict[str, str] = {"Authorization": f"Bearer {token()}"}

# Area sync
sync_url: str = f"https://{api_prefix()}-api.globalforestwatch.org/v2/area/sync"
# For some reason we are the only place calling this RW API to sync
# new subscriptions with areas. See GTC-2987 to fix this workflow.
yesterday = (datetime.now() - timedelta(1)).strftime("%Y-%m-%d")
sync_url: str = f"https://{api_prefix()}-api.globalforestwatch.org/v2/area/sync?startDate={yesterday}"
sync_resp = requests.post(sync_url, headers=headers)

if sync_resp.status_code != 200:
Expand Down

0 comments on commit 1f53010

Please sign in to comment.