private void registerPurgingTasks(String scriptFilePath) throws DeploymentException { File deploymentFileData = new File(scriptFilePath); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); log.info( "Deploying purging task : " + deploymentFileData.getName() + " for tenant : " + tenantId); try { AnalyticsDataPurgingConfiguration purgingConfiguration = getAnalyticsDataPurgingConfiguration(deploymentFileData); if (purgingConfiguration != null) { if (purgingConfiguration.getPurgingIncludeTables() != null) { TaskManager taskManager = AnalyticsServiceHolder.getTaskService() .getTaskManager(Constants.ANALYTICS_DATA_PURGING); for (AnalyticsDataPurgingIncludeTable analyticsDataPurgingIncludeTable : purgingConfiguration.getPurgingIncludeTables()) { if (analyticsDataPurgingIncludeTable.getValue() != null && !analyticsDataPurgingIncludeTable.getValue().isEmpty()) { TaskInfo dataPurgingTask = createDataPurgingTask( analyticsDataPurgingIncludeTable.getValue(), purgingConfiguration.getCronExpression(), purgingConfiguration.getRetentionDays()); taskManager.registerTask(dataPurgingTask); taskManager.rescheduleTask(dataPurgingTask.getName()); } } } } } catch (TaskException e) { log.error( "Unable to get task manager instance for ANALYTICS_DATA_PURGING:" + e.getMessage(), e); } }
public boolean reschedule(String taskName, TaskDescription taskDescription) { if (!isInitialized()) { return false; } try { synchronized (lock) { TaskInfo taskInfo = taskManager.getTask(taskName); TaskDescription description = TaskBuilder.buildTaskDescription(taskInfo); taskInfo = TaskBuilder.buildTaskInfo(description, properties); taskManager.registerTask(taskInfo); taskManager.rescheduleTask(taskInfo.getName()); } } catch (Exception e) { return false; } return true; }