/**
 * 
 */
package org.springblade.etl.task.thread;

import org.springblade.etl.task.service.DaemonTask;

import lombok.extern.slf4j.Slf4j;

/**
 * @author wookvn
 *
 */
@Slf4j
public class TaskWorker implements Runnable {
	
	private volatile boolean running = true;

    private TaskQueue<DaemonTask> queue;

    public TaskWorker(TaskQueue<DaemonTask> queue) {
        this.queue = queue;
    }

	@Override
	public void run() {
		while (running) {
            DaemonTask daemonTask = queue.dequeue();
            if (daemonTask != null) {
                try {
                    daemonTask.deal();
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
	}

	/**
	 * 
	 */
	public void shutdown() {
        running = false;
    }
}
