com.alibaba.dts.client.executor.grid.timer.TaskDeleteTimer Maven / Gradle / Ivy
package com.alibaba.dts.client.executor.grid.timer;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import com.alibaba.dts.client.executor.job.context.ClientContext;
import com.alibaba.dts.client.executor.job.context.ClientContextImpl;
import com.alibaba.dts.client.store.access.TaskSnapshotAccess;
import com.alibaba.dts.common.logger.SchedulerXLoggerFactory;
import com.alibaba.dts.common.logger.innerlog.Logger;
/**
* @author Ronan Zhan
* @date 2016/10/19.
*/
public class TaskDeleteTimer {
private static final Logger logger = SchedulerXLoggerFactory.getLogger(TaskDeleteTimer.class);
private ClientContextImpl clientContext;
public TaskDeleteTimer(ClientContextImpl clientContext) {
this.clientContext = clientContext;
}
public void init() {
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
clientContext.getStore().getTaskSnapshotDao().deleteFinishedTasks();
} catch (Throwable throwable) {
logger.error(throwable.getMessage(), throwable);
}
}
}, 0, 60, TimeUnit.SECONDS);
}
}