# Executing Agent Task Idle Status

**URL:** <https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868>\
**Category:** Module Development\
**Created:** [August 18, 2020, 4:29pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868 "2020-08-18T16:29:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![INNO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/inno/32/30161_2.png) [@INNO](https://forum.inductiveautomation.com/u/INNO)\
**Post date:** [August 18, 2020, 4:29pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/1 "2020-08-18T16:29:19Z")

</div>

Hi,

We have a module which generates Executing Agent Tasks to ping a specific IP at a particular rate. What we are seeing is at seemingly random times the status (Throughput) changes from xxx exec/sec to “Idle”.

What could be the cause?  
Can or should they be revived? if so, how?

Thank you in advance

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/c/7c8a0d36c388241250a0824b40ba1f6a13d96a56.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/d/cd633e5aec68124f6a92c8ec1665dd8c9b3fab84.png)

including: @mgross

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 18, 2020, 9:47pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/2 "2020-08-18T21:47:16Z")

</div>

Do you mean that your module registers tasks with the ExecutionManager from GatewayContext? Or are you talking about something else?

---

<div class="post-metadata">

**Author:** ![INNO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/inno/32/30161_2.png) [@INNO](https://forum.inductiveautomation.com/u/INNO)\
**Post date:** [August 18, 2020, 9:50pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/3 "2020-08-18T21:50:01Z")

</div>

I apologize if I was not clear. That correct, module registers tasks and the task runs are a particular rate. then the throughput turns idle.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 18, 2020, 9:56pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/4 "2020-08-18T21:56:10Z")

</div>

Here’s some things you can try:

Have you checked the logs for any exceptions running the task? Taken a thread dump once it goes idle to see if the tasks have blocked for some reason? Make sure there’s no code unregistering the tasks for some reason? Add logging to the task at the start and finish?

---

<div class="post-metadata">

**Author:** ![INNO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/inno/32/30161_2.png) [@INNO](https://forum.inductiveautomation.com/u/INNO)\
**Post date:** [August 21, 2020, 7:21pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/5 "2020-08-21T19:21:41Z")

</div>

A list of workers under ExecutionManager has been created which become “idle”. I can not find a method to get a list of them with their status from com.inductiveautomation.ignition.common.execution.ExecutionManager

How can i get the status of each worker?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 21, 2020, 7:40pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/6 "2020-08-21T19:40:01Z")

</div>

If you cast the ExecutionManager to `com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine` you can call `getTasks(String)` with the owner name you’re using to get a list of `TaskStat`. There should be one for every registered task.

---

<div class="post-metadata">

**Author:** ![INNO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/inno/32/30161_2.png) [@INNO](https://forum.inductiveautomation.com/u/INNO)\
**Post date:** [August 31, 2020, 2:59pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/7 "2020-08-31T14:59:07Z")

</div>

Please excuse my lack of Java skills, I cant get this to work, following return an empty list:

in Startup() I have

```auto
				watchDogClass watchDog = new watchDogClass();
				context.getExecutionManager().register("Testing", "connection monitor", watchDog, 500);
				
				

```

then in watchDog() I have:

```auto
			BasicExecutionEngine myExecutionEngine = new BasicExecutionEngine();
			List<TaskStats> myTasks = myExecutionEngine.getTasks("Testing");
			logger.info(myTasks);

// for(int i = 0; i < myTasks.size(); i++) {
// logger.info(i);
// logger.info(myTasks.get(i).getTaskName());
// logger.info(myTasks.get(i).isRunning());
// logger.info(myTasks.get(i).getProblem());
// }

```

I also tried the following method but i wouldn’t be able to call getTasks() :

```auto
ExecutionManager myExecutionEngine2 = new BasicExecutionEngine();

```

Cant find any example codes

---

<div class="post-metadata">

**Author:** ![Kevin.McClusky](https://avatars.discourse-cdn.com/v4/letter/k/47e85d/32.png) [@Kevin.McClusky](https://forum.inductiveautomation.com/u/Kevin.McClusky)\
**Post date:** [September 1, 2020, 7:14pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/8 "2020-09-01T19:14:11Z")

</div>

You'll want to cast the ExecutionManager to a BasicExecutionEngine. This would be a Java class cast. (Feel free to Google casting in Java it if you need more details on how this works.)

The basic code would be something like this:

> BasicExecutionEngine myExecutionEngine = (BasicExecutionEngine) context.getExecutionManager()

Then calling .getTasks("Testing") should work.

What you have in your second block of code is creating an entirely new, empty BasicExecutionEngine() rather than taking the existing ExecutionEngine and casting it to a BasicExecutionEngine.

---

<div class="post-metadata">

**Author:** ![INNO](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/inno/32/30161_2.png) [@INNO](https://forum.inductiveautomation.com/u/INNO)\
**Post date:** [September 2, 2020, 1:15pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/9 "2020-09-02T13:15:51Z")

</div>

Thanks Kevin,

I was able to cast the manager to my engine and now see my tasks. Im trying to get the specific task “problem”. so I thought to `getStatMetric()` monitor the throughput for -1 then `getProblem()`. but its always empty.

```
			try {
				if (myTaskMetric.getThroughput() == -1 ) { // -1 means the thread is idle
					logger.info("Detected an idle Thread");
					logger.info(myTasks.get(i).getProblem().getMessage());
					logger.info(myTasks.get(i).getProblem().getStackTrace()[0]);
					//myTasks.get(i).start(); //this will trigger to run the thread again
				}
			} catch (Exception e) {
				myTasks.get(i).getProblem().printStackTrace();
				e.printStackTrace();
			}

```

in log i see my watchDog thread “threw uncaught exception.”  
`java.lang.NullPointerException: null`

any ideas?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 2, 2020, 2:03pm UTC](https://forum.inductiveautomation.com/t/executing-agent-task-idle-status/37868/10 "2020-09-02T14:03:07Z")

</div>

> [@INNO](#):
>
> in log i see my watchDog thread “threw uncaught exception.”

That would be a bug in your watchdog thread. You need to have your watchdog catch its own errors and log them. Then you'll have a more informative backtrace.
