Reputation: 75
Is there a way to filter jobs using the tableau REST API according to task ID?
I have an extract refresh task I want to run on demand using /runNow but I want to perform a check to see if a job with this task is already currently running.
I haven't found much information online addressing this case.
First I was going to extract the extractRefresh taskID I am looking for and then filter through the jobs endpoint to see if any of them are joined with this ID. It seems like there's no way to filter in this way though. See below.
public bool CheckIfExtractRefreshIsRunning()
{
bool isRunning = false;
// Sign in here
try
{
string url = $"{server}/api/{version}/sites/{site}/tasks/extractRefreshes";
WebRequest req = WebRequest.Create(url);
webRequest.Headers.Add("X-Tableau-Auth", token);
WebResponse response;
response = req.GetResponse();
// Get XMLDocument response
var tasks = xmlDoc.SelectNodes("//task", nsManager);
foreach (XmlNode itemXml in tasks)
{
string taskID;
// Get task ID from tasks
if (sched == schedName)
{
//Filter through jobs here
url = $"{server}/api/{version}/sites/{site}/jobs?filter=args:has:{taskID}";
}
}
}
catch (Exception e)
{
throw e;
}
return isRunning;
}
Upvotes: 1
Views: 52
Reputation: 791
I could come up with two different options:
Since you're pulling the taskIDs already, just check the "state" of the task in question. If it is running, you have your answer.
URI
GET /api/api-version/sites/site-id/tasks/extractRefreshes/task-id
See Tableau documentation here.
Note: This approach is pretty janky even by my standards.
Compare your computer's local time with the scheduled start time of the extract refresh in question. If you know that all your extracts should be done within say 30 minutes, just write in a buffer after you grab the taskID's start time. Would not recommend this approach, but may work in a pinch.
See Tableau documentation here.
Upvotes: 0