aristanetworks/cvprac

No return for the method "execute_task"

Closed this issue · 5 comments

Hi,
The method "execute_task" doesn't get the result of the task execution even though the API entry point returns the status of the task:

ex:

response_stask = clnt.post('/task/executeTask.do', data=task_dict)
print(response_stask)

Is it by design?

@AJNOURI Yes this is by design. It's an asynchronous call. If you'd like to see the status for an individual task you can perform the following for a task:

task_status = clnt.get('/task/getTaskById.do?taskId=%s' % task_id)

Can we add a return value to this function otherwise you miss the error/success messages returned by the API call.
On success -
{
"data": "Task execution triggered successfully"
}
or on Failure -
{
"errorCode": "142612",
"errorMessage": "Execution failed due to invalid task status"
}
or similar.
This avoids the situation where a script has tried to execute a task that has a status that is not "Pending" or "Failed" and is unable to detect that the task has not been executed. Using the getTaskById option does not return the error code from the original executeTask call.

@Hugh-Adams I believe the underlying client checks and handles these errors by raising a Exception:

def _is_good_response(self, response, prefix):

You would need to wrap the API call in a try/except and should be able to inspect the exception.

@cheynearista Agreed you could and you would get the following:

"POST: https://10.83.30.100:443/web/task/executeTask.do : Request Error: Execution failed due to invalid task status"

which to me isn't as simple to handle as

{
"errorCode": "142612",
"errorMessage": "Execution failed due to invalid task status"
}

if I get the return from the API call, or am I missing something?

I can add the return data to this function but I don't think it guarantees the task status is returned. The way to make sure you get a tasks status is to do the getTaskById API as Cheyne mentioned. The errors will continue to be processed within an exception instead of returning them in string output for some cases.