{= # # # # cancel_task.cfv # # # include "templates.util.base_util"; include "templates.util.encoding"; debug_message("\n\n\n#### progress/cancel_task.cfv START \n\n"); # # # Check permissions # # string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); bool is_cancel_task_permission = false; string page_token = v.fp.page_token; if (!is_root_admin) then ( string profile_name = internal.profile_name; node super_role = get_super_role_of_profile(session_id, profile_name); is_cancel_task_permission = (?(super_role . ".reports.cancel_task") or ?(super_role . ".config.cancel_task")); ); if ((is_root_admin or is_cancel_task_permission) and get_is_valid_page_token(session_id, "progress", 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 dat:\n" . dat . "\n\n"); "progress.cancelTaskResponse(" . dat . ")\n"; ) else ( display_no_permission_html(); ); =}