Skip to content

Commit d95d3cc

Browse files
committed
Feat: Default view create after flow got success
1 parent 2771231 commit d95d3cc

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

ckanext/preflow/logic/action.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,45 @@ def preflow_status_update(
231231
"error": "" if clear_log else (json.dumps(error) if error else None),
232232
}
233233

234-
return tk.get_action("task_status_update")(context, task_dict)
234+
result = tk.get_action("task_status_update")(context, task_dict)
235+
tk.get_action("preflow_hook")(
236+
context,
237+
{
238+
"resource_id": resource_id,
239+
"flow_run_id": flow_run_id,
240+
},
241+
)
242+
243+
return result
235244

236245

237246
def preflow_hook(context: Context, data_dict: dict[str, str]) -> dict[str, str]:
238-
pass
247+
"""
248+
Preflow hook to handle resource post submission actions after prflow status update.
249+
Generally used to create the views for the resource.
250+
"""
251+
252+
res_id = tk.get_or_bust(data_dict, "resource_id")
253+
254+
tk.check_access("preflow_submit", context, data_dict)
255+
256+
status = tk.get_action("preflow_status")(
257+
context,
258+
{"id": res_id, "flow_run_id": data_dict.get("flow_run_id", "")},
259+
)
260+
261+
if status.get("state", "").lower() not in ["completed"]:
262+
resource_dict = p.toolkit.get_action("resource_show")(context, {"id": res_id})
263+
264+
dataset_dict = p.toolkit.get_action("package_show")(
265+
context, {"id": resource_dict["package_id"]}
266+
)
267+
268+
p.toolkit.get_action("resource_create_default_resource_views")(
269+
context,
270+
{
271+
"resource": resource_dict,
272+
"package": dataset_dict,
273+
"create_datastore_views": True,
274+
},
275+
)

0 commit comments

Comments
 (0)