Skip to content

Commit

Permalink
fix: check whether dataset is activated before activating it
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 8, 2024
1 parent b185d52 commit 0b243f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.15.3
- fix: check whether dataset is activated before activating it
- fix: timeout after 500 s in dataset_activate in case
the server is under heavy load
0.15.2
Expand Down
26 changes: 18 additions & 8 deletions dcoraid/api/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import requests
from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor

from ..common import ConnectionTimeoutErrors

from .errors import (
APIBadRequest, APIConflictError, APINotFoundError, NoS3UploadAvailableError
)
Expand All @@ -31,14 +33,22 @@ def dataset_activate(dataset_id: str, api: CKANAPI):
api: dcoraid.api.CKANAPI
API instance with server, api_key (and optional certificate)
"""
revise_dict = {
"match": {"id": dataset_id},
"update": {"state": "active"}}
api.post("package_revise",
revise_dict,
# Dataset activation may take long when there are a lot of
# resources.
timeout=500)
try:
# First check whether the dataset is already active. Use a long
# timeout for this critical step.
ds_dict = api.get("package_show", id=dataset_id, timeout=500)
except ConnectionTimeoutErrors:
raise
else:
if not ds_dict["state"] == "active":
revise_dict = {
"match": {"id": dataset_id},
"update": {"state": "active"}}
api.post("package_revise",
revise_dict,
# Dataset activation may take long when there
# are a lot of resources.
timeout=500)


def dataset_create(dataset_dict, api, resources=None,
Expand Down

0 comments on commit 0b243f4

Please sign in to comment.