Search in sources :

Example 1 with PointInTimeTrigger

use of org.kie.kogito.timer.impl.PointInTimeTrigger in project kogito-apps by kiegroup.

the class BaseJobRepositoryTest method createAndSaveJob.

private void createAndSaveJob(String id) throws Exception {
    job = JobDetails.builder().id(id).trigger(// 
    new PointInTimeTrigger(System.currentTimeMillis(), null, null)).priority(1).recipient(new Recipient.HTTPRecipient("url")).build();
    tested().save(job).toCompletableFuture().get();
}
Also used : Recipient(org.kie.kogito.jobs.service.model.job.Recipient) PointInTimeTrigger(org.kie.kogito.timer.impl.PointInTimeTrigger)

Example 2 with PointInTimeTrigger

use of org.kie.kogito.timer.impl.PointInTimeTrigger in project kogito-apps by kiegroup.

the class VertxTimerServiceSchedulerTest method schedule.

private ManageableJobHandle schedule(ZonedDateTime time) {
    final long timestamp = time.toInstant().toEpochMilli();
    trigger = new PointInTimeTrigger(timestamp, null, null);
    jobDetails = JobDetails.builder().build();
    context = new HttpJobContext(jobDetails);
    job = new HttpJob(executor);
    return tested.scheduleJob(job, context, trigger);
}
Also used : PointInTimeTrigger(org.kie.kogito.timer.impl.PointInTimeTrigger) HttpJobContext(org.kie.kogito.jobs.service.model.job.HttpJobContext) HttpJob(org.kie.kogito.jobs.service.model.job.HttpJob)

Example 3 with PointInTimeTrigger

use of org.kie.kogito.timer.impl.PointInTimeTrigger in project kogito-apps by kiegroup.

the class TriggerMarshaller method readFrom.

@Override
public Trigger readFrom(ProtoStreamReader reader) throws IOException {
    String classType = reader.readString("classType");
    Date startTime = fromInstant(reader.readInstant("startTime"));
    Date endTime = fromInstant(reader.readInstant("endTime"));
    Integer repeatLimit = reader.readInt("repeatLimit");
    Integer repeatCount = reader.readInt("repeatCount");
    Date nextFireTime = fromInstant(reader.readInstant("nextFireTime"));
    Long period = reader.readLong("period");
    return Optional.ofNullable(classType).filter(IntervalTrigger.class.getName()::equals).<Trigger>map(c -> {
        IntervalTrigger intervalTrigger = new IntervalTrigger();
        intervalTrigger.setStartTime(startTime);
        intervalTrigger.setEndTime(endTime);
        intervalTrigger.setRepeatLimit(repeatLimit);
        intervalTrigger.setRepeatCount(repeatCount);
        intervalTrigger.setNextFireTime(nextFireTime);
        intervalTrigger.setPeriod(period);
        return intervalTrigger;
    }).orElseGet(() -> Optional.ofNullable(nextFireTime).map(Date::getTime).map(t -> new PointInTimeTrigger(t, null, null)).orElse(null));
}
Also used : Trigger(org.kie.kogito.timer.Trigger) PointInTimeTrigger(org.kie.kogito.timer.impl.PointInTimeTrigger) Date(java.util.Date) Optional(java.util.Optional) IntervalTrigger(org.kie.kogito.timer.impl.IntervalTrigger) IOException(java.io.IOException) PointInTimeTrigger(org.kie.kogito.timer.impl.PointInTimeTrigger) Date(java.util.Date) IntervalTrigger(org.kie.kogito.timer.impl.IntervalTrigger)

Example 4 with PointInTimeTrigger

use of org.kie.kogito.timer.impl.PointInTimeTrigger in project kogito-apps by kiegroup.

the class TriggerMarshallerTest method marshallPointInTimeTriggerAccessor.

@Test
void marshallPointInTimeTriggerAccessor() {
    Date time = new Date();
    PointInTimeTrigger trigger = new PointInTimeTrigger(time.getTime(), null, null);
    JsonObject jsonObject = marshaller.marshall(trigger);
    assertEquals(new JsonObject().put("nextFireTime", time.getTime()).put("classType", PointInTimeTrigger.class.getName()), jsonObject);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) PointInTimeTrigger(org.kie.kogito.timer.impl.PointInTimeTrigger) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with PointInTimeTrigger

use of org.kie.kogito.timer.impl.PointInTimeTrigger in project kogito-apps by kiegroup.

the class TriggerMarshallerTest method unmarshallPointInTimeTriggerAccessor.

@Test
void unmarshallPointInTimeTriggerAccessor() {
    Date time = new Date();
    JsonObject jsonObject = new JsonObject().put("nextFireTime", time.getTime()).put("classType", PointInTimeTrigger.class.getName());
    Trigger trigger = marshaller.unmarshall(jsonObject);
    assertEquals(new PointInTimeTrigger(time.getTime(), null, null).toString(), trigger.toString());
}
Also used : Trigger(org.kie.kogito.timer.Trigger) PointInTimeTrigger(org.kie.kogito.timer.impl.PointInTimeTrigger) IntervalTrigger(org.kie.kogito.timer.impl.IntervalTrigger) JsonObject(io.vertx.core.json.JsonObject) PointInTimeTrigger(org.kie.kogito.timer.impl.PointInTimeTrigger) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

PointInTimeTrigger (org.kie.kogito.timer.impl.PointInTimeTrigger)18 Test (org.junit.jupiter.api.Test)9 JobDetails (org.kie.kogito.jobs.service.model.job.JobDetails)9 JsonObject (io.vertx.core.json.JsonObject)8 Recipient (org.kie.kogito.jobs.service.model.job.Recipient)7 ZonedDateTime (java.time.ZonedDateTime)5 Date (java.util.Date)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Trigger (org.kie.kogito.timer.Trigger)5 JobStatus (org.kie.kogito.jobs.service.model.JobStatus)3 Multi (io.smallrye.mutiny.Multi)2 Uni (io.smallrye.mutiny.Uni)2 Tuple (io.vertx.mutiny.sqlclient.Tuple)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ScheduledJob (org.kie.kogito.jobs.service.model.ScheduledJob)2 IntervalTrigger (org.kie.kogito.timer.impl.IntervalTrigger)2 FindOneAndReplaceOptions (com.mongodb.client.model.FindOneAndReplaceOptions)1 FindOptions (io.quarkus.mongodb.FindOptions)1 ReactiveMongoClient (io.quarkus.mongodb.reactive.ReactiveMongoClient)1 ReactiveMongoCollection (io.quarkus.mongodb.reactive.ReactiveMongoCollection)1