Search in sources :

Example 21 with ScheduledJob

use of com.enonic.xp.scheduler.ScheduledJob in project xp by enonic.

the class BaseScheduledJobHandlerTest method updateLastRun.

protected void updateLastRun(final ScheduledJobName name) {
    final ScheduledJob existJob = jobs.get(name);
    final ScheduledJob modifiedJob = ScheduledJob.create().name(existJob.getName()).description(existJob.getDescription()).calendar(existJob.getCalendar()).enabled(existJob.isEnabled()).descriptor(existJob.getDescriptor()).config(existJob.getConfig()).user(existJob.getUser()).creator(existJob.getCreator()).createdTime(existJob.getCreatedTime()).modifier(existJob.getModifier()).modifiedTime(existJob.getModifiedTime()).lastTaskId(TaskId.from("task-id")).lastRun(Instant.parse("2021-02-25T10:44:33.170079900Z")).build();
    jobs.put(name, modifiedJob);
}
Also used : ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) EditableScheduledJob(com.enonic.xp.scheduler.EditableScheduledJob)

Example 22 with ScheduledJob

use of com.enonic.xp.scheduler.ScheduledJob in project xp by enonic.

the class CreateScheduledJobHandler method doExecute.

@Override
protected ScheduledJobMapper doExecute() {
    final CreateScheduledJobParams params = createParams();
    final ScheduledJob scheduledJob = this.schedulerService.get().create(params);
    return ScheduledJobMapper.from(scheduledJob);
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob)

Example 23 with ScheduledJob

use of com.enonic.xp.scheduler.ScheduledJob in project xp by enonic.

the class SchedulerResourceTest method list.

@Test
public void list() throws Exception {
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing");
    final CronCalendar cronCalendar = new CronCalendar() {

        @Override
        public String getCronValue() {
            return "* * * * *";
        }

        @Override
        public TimeZone getTimeZone() {
            return TimeZone.getTimeZone("GMT+3:00");
        }

        public Optional<Duration> nextExecution() {
            return Optional.of(Duration.ofSeconds(50));
        }

        @Override
        public ScheduleCalendarType getType() {
            return ScheduleCalendarType.CRON;
        }
    };
    final OneTimeCalendar oneTimeCalendar = new OneTimeCalendar() {

        @Override
        public Instant getValue() {
            return Instant.parse("2016-11-02T10:36:00Z");
        }

        @Override
        public Optional<Duration> nextExecution() {
            return Optional.of(Duration.ofSeconds(50));
        }

        @Override
        public ScheduleCalendarType getType() {
            return ScheduleCalendarType.ONE_TIME;
        }
    };
    final PropertyTree config = new PropertyTree();
    config.addString("string", "value");
    final ScheduledJob job1 = ScheduledJob.create().name(ScheduledJobName.from("test1")).descriptor(descriptor).calendar(cronCalendar).config(config).enabled(true).description("description").creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:modifier")).user(PrincipalKey.from("user:system:user")).lastRun(Instant.parse("2012-01-01T00:00:00.00Z")).lastTaskId(TaskId.from("task-id")).createdTime(Instant.parse("2010-01-01T00:00:00.00Z")).modifiedTime(Instant.parse("2011-02-01T00:00:00.00Z")).lastRun(Instant.parse("2012-01-01T00:00:00.00Z")).build();
    final ScheduledJob job2 = ScheduledJob.create().name(ScheduledJobName.from("test2")).descriptor(descriptor).calendar(oneTimeCalendar).creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:modifier")).createdTime(Instant.parse("2010-01-01T00:00:00.00Z")).modifiedTime(Instant.parse("2011-02-01T00:00:00.00Z")).build();
    Mockito.when(schedulerService.list()).thenReturn(List.of(job1, job2));
    final String result = request().path("scheduler/list").get().getAsString();
    assertJson("list_scheduled_jobs.json", result);
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) PropertyTree(com.enonic.xp.data.PropertyTree) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) DescriptorKey(com.enonic.xp.page.DescriptorKey) Duration(java.time.Duration) Test(org.junit.jupiter.api.Test)

Aggregations

ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)23 PropertyTree (com.enonic.xp.data.PropertyTree)14 Test (org.junit.jupiter.api.Test)13 DescriptorKey (com.enonic.xp.page.DescriptorKey)11 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)10 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)10 PrincipalKey (com.enonic.xp.security.PrincipalKey)9 EditableScheduledJob (com.enonic.xp.scheduler.EditableScheduledJob)7 Instant (java.time.Instant)7 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)6 CronCalendar (com.enonic.xp.scheduler.CronCalendar)6 ModifyScheduledJobParams (com.enonic.xp.scheduler.ModifyScheduledJobParams)6 ScheduleCalendar (com.enonic.xp.scheduler.ScheduleCalendar)6 Context (com.enonic.xp.context.Context)5 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)5 AuditLogService (com.enonic.xp.audit.AuditLogService)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4 OneTimeCalendar (com.enonic.xp.scheduler.OneTimeCalendar)4 IdProviderKey (com.enonic.xp.security.IdProviderKey)4 User (com.enonic.xp.security.User)4