taskInfo: Get the details of the task

Function Description:

Get the details of the task based on the task name.

Corresponding JS API:
taskInfo(taskName)
Whether to support multiple devices:

No

Version:

For Total Control version 6.9.0 and higher

Resource Information:

Method GET
URL .../tasks/:task_name
Requires authentication? Yes


Method Parameters:

Parameter Type Required Description
task_name String Yes Task name


Response Parameters:

A JSON string representing an array of objects with the following fields:

Field Type Description
status Boolean Return true for success and null for failure
value JSON/String (String) If the value of status is a null object, an error message or empty string is returned.
(JSON) If the value of status is true, returns the details of the task, in the format json object, containing the following fields:
- task_id: (Long) Task id.
- task_name: (String) Task name.
- script_file: (String) Script file.
- status: (Int) Task status.
There are several states.
     0: The script file does not exist;
    -1: Running;
    -2: Normal stop;
    -3: Abnormal stop;
    -4: Pause;
    -5: User terminated;
    -6: Scheduled tasks (unexecuted scheduled tasks);
- error_message: (String) Error message. When the value of status is -3, error_message returns an exception error message. When the value of status is not -3, error_message is empty.
- total_iterations: (Int) The total number of iterations.
- current_iteration: (Int) Current iterations.
- start_time: (Date) The time to start executing the script.
- end_time: (Date) The time the script ended execution.
- schedule: (Date) Task execution time.


Request Example:
http://localhost:8090/TotalControl/v1/tasks/task004?token=270eq7lXQK8bXYsJ
Response Example:

If this API executes successfully, it returns:

{
    "status":true,
    "value":{
        "task_id":1551113151878,
        "task_name":"task01",
        "script_file":"C:\Users\sigma\Documents\Scripts\1.js",
        "status":-6,
        "total_iterations":1,
        "current_iteration":1,
        "start_time":"2019-02-21 22:17:00",
        "schedule":"2019-02-21 22:17:00",
        "error_message":""
    }
}

If the value of HTTP status code is 200, but the value of status is a null object, it returns:

{
    "status": null,
    "value": "<Error message>"
}


Example:

Warm tip:
Get the token needed for Total Control script development,see here.

RingoJS Example:
// Import the packages
var {request} = require("ringo/httpclient");
var base64 = require("ringo/base64");

// The username and password are separated by a single : and sent on the wire base64 encoded
var userpass = base64.encode("sigma:3D391497");

// First step: Get the API token
var gettoken = request({
	method: "GET",
	url: "http://localhost:8090/TotalControl/v1/login",
	headers: {
		"Authorization": userpass
	}
});
var ret_token = JSON.parse(gettoken.content); 
var token = ret_token.value.token; 
print("//The value of token is:" + token);

// Second step: Execute this REST API
var resp = request({
	method: "GET",
	url: "http://localhost:8090/TotalControl/v1/tasks/task002",
	data: {
		"token": token
	}
});
var obj = JSON.parse(resp.content); 
ret =obj.status;
if (ret == true) {
	print("//Executed successfully,Return value: \n"+resp.content);	
} else if (ret != true & resp.status == 200){
	print("An error message is returned: "+resp.content);
} else {
	print("This API failed to execute.");
}
The running result of the RingoJS:

If it executes successfully, it will return:

//The value of token is:veLZf8EL7gUoyFOL
//Executed successfully,Return value: 
{
	"status": true,
	"value": {
		"task_id": 1554980489130,
		"task_name": "task002",
		"script_file": "C:\\Users\\sigma\\Documents\\Scripts\\getname.js",
		"status": -6,
		"total_iterations": 1,
		"current_iteration": 1,
		"start_time": "2019-04-17 18:50:00",
		"schedule": "2019-04-17 18:50:00",
		"error_message": ""
	}
}
Python Example:
#!/user/bin/python
#-*- coding:utf-8 -*-
import base64
import requests

# The username and password are separated by a single : and sent on the wire base64 encoded
user_pass = 'sigma:3D391497'
encodeStr = base64.b64encode(user_pass.encode("UTF-8"))

# First step: Get the API token
LoginUrl = "http://localhost:8090/TotalControl/v1/login"
response = requests.get(LoginUrl, headers={'Authorization':encodeStr})
print("Get the token,Return value: ",response.json())
token = response.json()['value']['token']
print("The value of token is: ",token)

# Second step: Execute this REST API
if token is not None:
    APIUrl = "http://localhost:8090/TotalControl/v1/tasks/task001"
    data = {
        "token": token
    }
    response = requests.get(url=APIUrl, params=data)
    ret = response.json()['status']
    # Determine if this REST API is executed successfully
    if ret is True:
        print("Executed successfully,Return value: ", response.json())
    elif response.status_code == 200 and ret is not True:
        print("An error message is returned: ",response.json())
    else:
        print("This API failed to execute.")
else:
    print("Failed to get token.")
The running result of the python:

If it executes successfully, it will return:

Get the token,Return value:  {'status': True, 'value': {'token': 'veLZf8EL7gUoyFOL'}}
The value of token is:  veLZf8EL7gUoyFOL
Executed successfully,Return value:  {'status': True, 'value': {'task_id': 1557305002116, 'task_name': 'task001', 'script_file': 'C:\\Users\\sigma\\Documents\\Scripts\\getname.js', 'status': -2, 'total_iterations': 1, 'current_iteration': 1, 'start_time': '2019-04-17 15:34:32', 'end_time': '2019-04-17 15:34:32', 'error_message': ''}}