{= # # # # cancel_task.cfv # # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.encoding"; debug_message("\n\n\n#### admin_pages/tasks/cancel_task.cfv \n\n"); string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); string page_token = v.fp.page_token; # # Check RBAC permissions # if ((is_root_admin or get_admin_feature_permission(session_id, "tasks", "view")) and get_is_valid_page_token(session_id, "tasks", page_token)) then ( debug_message("\n" . node_as_string("v.fp") . "\n"); string task_id = v.fp.task_id; # Check if the task is still active bool is_active_task = get_is_active_task(task_id); bool isError = false; string errorMessage; if (is_active_task) then ( cancel_task(task_id); # # Wait until the task is not anymore active, this may take some time, # we wait for at least 60 seconds # int count = 0; int time_in_ms = 1000; while (is_active_task and count < 60) ( sleep_milliseconds(time_in_ms); is_active_task = get_is_active_task(task_id); count++; ); debug_message("#### Task cancellation took about " . time_in_ms * count . " milliseconds \n"); ) else ( isError = true; errorMessage = lang_admin.tasks.task_already_completed; ); string dat = "{"; dat .= add_json("isError", isError, "bool"); dat .= add_json("errorMessage", errorMessage, "string"); dat = close_json(dat); debug_message("\n\n#### cancel_task.cfv response dat:\n" . dat . "\n\n"); "tasks.cancelTaskResponse(" . dat . ")\n"; ) else ( # No permission to access this resource (URL) display_no_permission_html(); ); =}