mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
28.42.2018 ea69c28b8aa40b0de84e3ec52941d08ae9ef6cef
borgbutler-core/src/main/java/de/micromata/borgbutler/jobs/JobQueue.java
@@ -9,6 +9,7 @@
import java.util.concurrent.Executors;
public class JobQueue {
    private static final int MAX_DONE_JOBS_SIZE = 50;
    private Logger log = LoggerFactory.getLogger(JobQueue.class);
    private List<AbstractJob> queue = new ArrayList<>();
    private List<AbstractJob> doneJobs = new LinkedList<>();
@@ -19,6 +20,10 @@
        return queue.size();
    }
    public List<AbstractJob> getDoneJobs() {
        return Collections.unmodifiableList(doneJobs);
    }
    /**
     * Appends the job if not alread in the queue. Starts the execution if no execution thread is already running.
     *
@@ -79,6 +84,9 @@
                    it.remove();
                    doneJobs.add(0, job);
                }
                while (doneJobs.size() > MAX_DONE_JOBS_SIZE) {
                    doneJobs.remove(doneJobs.size() - 1);
                }
            }
        }
    }
@@ -112,7 +120,10 @@
                    log.info("Starting job: " + job.getId());
                    job.setStatus(AbstractJob.Status.RUNNING);
                    job.execute();
                    job.setStatus(AbstractJob.Status.DONE);
                    if (!job.isFinished()) {
                        // Don't overwrite status failed set by job.
                        job.setStatus(AbstractJob.Status.DONE);
                    }
                } catch (Exception ex) {
                    log.error("Error while executing job '" + job.getId() + "': " + ex.getMessage(), ex);
                    job.setStatus(AbstractJob.Status.FAILED);