|
1 | 1 | import datetime |
2 | 2 | import json |
| 3 | +import logging |
| 4 | +import time |
3 | 5 |
|
4 | 6 | from ckan import logic |
5 | 7 | import dclab |
|
10 | 12 | from dcor_shared import RQJob # noqa: F401 |
11 | 13 |
|
12 | 14 |
|
| 15 | +logger = logging.getLogger(__name__) |
| 16 | + |
| 17 | + |
13 | 18 | def admin_background_context(): |
14 | 19 | return {"ignore_auth": True, |
15 | 20 | "user": "default", |
@@ -70,16 +75,25 @@ def job_set_resource_metadata_base(resource): |
70 | 75 | # Do not compare against `resource`, because this dictionary might |
71 | 76 | # not be the one that we have in the database. |
72 | 77 | resource_show = logic.get_action("resource_show") |
73 | | - res_dict_act = resource_show(context={'ignore_auth': True, |
74 | | - 'user': 'default'}, |
75 | | - data_dict={"id": resource['id']}) |
| 78 | + changes_required = False |
76 | 79 |
|
77 | | - for key in res_dict_base: |
78 | | - if res_dict_base[key] != res_dict_act.get(key): |
79 | | - changes_required = True |
| 80 | + # be patient when showing the resource for the first time |
| 81 | + for ii in range(5): |
| 82 | + try: |
| 83 | + res_dict_act = resource_show(context=admin_background_context(), |
| 84 | + data_dict={"id": resource['id']}) |
| 85 | + except BaseException: |
| 86 | + logger.error(f"Could not fetch resource dict for {resource['id']}") |
| 87 | + time.sleep(0.5) |
| 88 | + else: |
| 89 | + for key in res_dict_base: |
| 90 | + if res_dict_base[key] != res_dict_act.get(key): |
| 91 | + changes_required = True |
| 92 | + break |
80 | 93 | break |
81 | 94 | else: |
82 | | - changes_required = False |
| 95 | + # Fall-back to applying the changes anyway |
| 96 | + changes_required = True |
83 | 97 |
|
84 | 98 | if changes_required: |
85 | 99 | res_dict_base["last_modified"] = datetime.datetime.now( |
|
0 commit comments