Fix issue in task watcher config

pull/65/head
Chamindu Senanayake 2 years ago
parent 49c3088a3f
commit 39020a8f91

@ -22,6 +22,8 @@ package io.entgra.task.mgt.watcher;
import io.entgra.task.mgt.common.bean.DynamicTask;
import io.entgra.task.mgt.common.constant.TaskMgtConstant;
import io.entgra.task.mgt.common.exception.TaskManagementException;
import io.entgra.task.mgt.core.config.TaskConfigurationManager;
import io.entgra.task.mgt.core.config.TaskManagementConfig;
import io.entgra.task.mgt.core.util.TaskManagementUtil;
import io.entgra.task.mgt.watcher.internal.TaskWatcherDataHolder;
import org.apache.commons.logging.Log;
@ -45,13 +47,25 @@ public class IoTSStartupHandler implements ServerStartupObserver {
@Override
public void completedServerStartup() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
compareTasks();
try {
TaskManagementConfig taskManagementConfig = TaskConfigurationManager.getInstance().getTaskManagementConfig();
if (taskManagementConfig.isTaskWatcherEnabled()) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
compareTasks();
}
}, 200000, 600000);
} else {
String msg = "Task watcher is not enabled in this environment hence wso2 carbon ntask will not " +
"update according to the task manager ";
log.error(msg);
}
}, 200000, 600000);
} catch (TaskManagementException e) {
String msg = "Unable to read task watcher configuration";
log.error(msg);
}
}
private void compareTasks() {
@ -97,7 +111,7 @@ public class IoTSStartupHandler implements ServerStartupObserver {
&& taskManager.getTaskState(generatedTaskId) != TaskManager.TaskState.PAUSED) {
taskManager.pauseTask(generatedTaskId);
}
log.info("Task - '" + generatedTaskId + "' updated according to the dynamic task table");
log.debug("Task - '" + generatedTaskId + "' updated according to the dynamic task table");
break;
}
}
@ -108,7 +122,7 @@ public class IoTSStartupHandler implements ServerStartupObserver {
dt.getProperties(), triggerInfo);
taskManager.registerTask(taskInfo);
taskManager.scheduleTask(generatedTaskId);
log.info("New task -'" + generatedTaskId + "' created according to the dynamic task table");
log.debug("New task -'" + generatedTaskId + "' created according to the dynamic task table");
}
}
@ -122,7 +136,7 @@ public class IoTSStartupHandler implements ServerStartupObserver {
}
if (!isExist) {
taskManager.deleteTask(taskInfo.getName());
log.info("Task '" + taskInfo.getName() + "' deleted according to the dynamic task table");
log.debug("Task '" + taskInfo.getName() + "' deleted according to the dynamic task table");
}
}
log.info("Task Comparison Completed and all tasks in current node are updated");

@ -55,15 +55,8 @@ public class TaskWatcherServiceComponent {
log.debug("Activating Task Watcher Service Component");
}
try {
TaskManagementConfig taskManagementConfig = TaskConfigurationManager.getInstance().getTaskManagementConfig();
if (taskManagementConfig.isTaskWatcherEnabled()) {
BundleContext bundleContext = ctx.getBundleContext();
bundleContext.registerService(ServerStartupObserver.class.getName(), new IoTSStartupHandler(), null);
} else {
String msg = "Task watcher is not enabled in this environment hence wso2 carbon ntask will not " +
"update according to the task manager ";
log.debug(msg);
}
BundleContext bundleContext = ctx.getBundleContext();
bundleContext.registerService(ServerStartupObserver.class.getName(), new IoTSStartupHandler(), null);
if (log.isDebugEnabled()) {
log.debug("Task Watcher Service Component has been successfully activated");
}

Loading…
Cancel
Save