All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.graylog.scheduler.JobTriggerUpdate Maven / Gradle / Ivy

There is a newer version: 6.1.4
Show newest version
/*
 * Copyright (C) 2020 Graylog, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Server Side Public License, version 1,
 * as published by MongoDB, Inc.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Server Side Public License for more details.
 *
 * You should have received a copy of the Server Side Public License
 * along with this program. If not, see
 * .
 */
package org.graylog.scheduler;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.auto.value.AutoValue;
import org.joda.time.DateTime;

import javax.annotation.Nullable;
import java.util.Optional;

@AutoValue
@JsonDeserialize(builder = JobTriggerUpdate.Builder.class)
public abstract class JobTriggerUpdate {
    public abstract Optional nextTime();

    public abstract Optional data();

    public abstract Optional status();

    public abstract boolean concurrencyReschedule();

    public static JobTriggerUpdate withNextTime(DateTime nextTime) {
        return builder().nextTime(nextTime).build();
    }

    /**
     * Reschedule a trigger because of a concurrency rejection.
     *
     * @param nextTime the next time the trigger should be retried
     * @return the job trigger update
     */
    public static JobTriggerUpdate withConcurrencyReschedule(DateTime nextTime) {
        return builder().concurrencyReschedule(true).nextTime(nextTime).build();
    }

    /**
     * Create job trigger update without next time. That means the trigger will not be scheduled anymore and will
     * be marked as {@link JobTriggerStatus#COMPLETE}.
     *
     * @return the job trigger update object
     */
    public static JobTriggerUpdate withoutNextTime() {
        return builder().nextTime(null).build();
    }

    public static JobTriggerUpdate withError(JobTriggerDto trigger) {
        // On error, we keep the previous nextTime
        return builder().nextTime(trigger.nextTime()).status(JobTriggerStatus.ERROR).build();
    }

    public static JobTriggerUpdate withStatusAndNoNextTime(JobTriggerStatus status) {
        return builder().nextTime(null).status(status).build();
    }

    public static JobTriggerUpdate withNextTimeAndData(DateTime nextTime, JobTriggerData data) {
        return builder().nextTime(nextTime).data(data).build();
    }

    public static Builder builder() {
        return Builder.create();
    }

    public abstract Builder toBuilder();

    @AutoValue.Builder
    public static abstract class Builder {
        @JsonCreator
        public static Builder create() {
            return new AutoValue_JobTriggerUpdate.Builder().concurrencyReschedule(false);
        }

        public abstract Builder nextTime(@Nullable DateTime nextTime);

        public abstract Builder data(@Nullable JobTriggerData data);

        public abstract Builder status(@Nullable JobTriggerStatus status);

        public abstract Builder concurrencyReschedule(boolean concurrencyReschedule);

        public abstract JobTriggerUpdate build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy