mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-27 14:23:56 +00:00
[AB-xx] improving scheduling interface
moving renaming module to int removing duplicated starboard feature validator sonar fixes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package dev.sheldan.abstracto.scheduling.service;
|
||||
|
||||
import dev.sheldan.abstracto.scheduling.factory.QuartzConfigFactory;
|
||||
import dev.sheldan.abstracto.scheduling.model.JobParameters;
|
||||
import dev.sheldan.abstracto.scheduling.model.database.SchedulerJob;
|
||||
import dev.sheldan.abstracto.scheduling.service.management.SchedulerJobManagementServiceBean;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -150,8 +151,10 @@ public class SchedulerServiceBean implements SchedulerService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executeJobWithParametersOnce(String name, String group, JobDataMap dataMap, Date date) {
|
||||
Trigger onceOnlyTriggerForJob = scheduleCreator.createOnceOnlyTriggerForJob(name, group, date, dataMap);
|
||||
public String executeJobWithParametersOnce(String name, String group, JobParameters dataMap, Date date) {
|
||||
JobDataMap map = new JobDataMap();
|
||||
dataMap.getParameters().keySet().forEach(o -> map.put(o.toString(), dataMap.getParameters().get(o)));
|
||||
Trigger onceOnlyTriggerForJob = scheduleCreator.createOnceOnlyTriggerForJob(name, group, date, map);
|
||||
try {
|
||||
schedulerFactoryBean.getScheduler().scheduleJob(onceOnlyTriggerForJob);
|
||||
return onceOnlyTriggerForJob.getKey().getName();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.scheduling.factory;
|
||||
|
||||
import dev.sheldan.abstracto.scheduling.model.JobParameters;
|
||||
import dev.sheldan.abstracto.scheduling.model.database.SchedulerJob;
|
||||
import dev.sheldan.abstracto.scheduling.service.SchedulerServiceBean;
|
||||
import dev.sheldan.abstracto.scheduling.service.management.SchedulerJobManagementServiceBean;
|
||||
@@ -98,7 +99,7 @@ public class SchedulerServiceBeanTest {
|
||||
public void executeJobOnce() throws SchedulerException {
|
||||
when(scheduleCreator.createOnceOnlyTriggerForJob(eq(JOB_NAME), eq(GROUP_NAME), any(Date.class), any(JobDataMap.class))).thenReturn(trigger);
|
||||
when(trigger.getKey()).thenReturn(TriggerKey.triggerKey("random key"));
|
||||
classToTest.executeJobWithParametersOnce(JOB_NAME, GROUP_NAME, new JobDataMap(), new Date());
|
||||
classToTest.executeJobWithParametersOnce(JOB_NAME, GROUP_NAME, JobParameters.builder().build(), new Date());
|
||||
verify(scheduler, times(1)).scheduleJob(any(Trigger.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.scheduling.model;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class JobParameters {
|
||||
@Builder.Default
|
||||
private Map<Object, Object> parameters = new HashMap<>();
|
||||
}
|
||||
@@ -22,36 +22,43 @@ public class SchedulerJob implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* The name of the job
|
||||
*/
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* The group of the job
|
||||
*/
|
||||
@Column(name = "group_name")
|
||||
private String groupName;
|
||||
|
||||
/**
|
||||
* The absolute path of a class extending {@link org.springframework.scheduling.quartz.QuartzJobBean} which should be executed by this job
|
||||
*/
|
||||
@Column(name = "clazz")
|
||||
private String clazz;
|
||||
|
||||
/**
|
||||
* If the job should be executed based on a cron expression, this contains this expression. If it is a one-time job this needs to be null.
|
||||
*/
|
||||
@Column(name = "cron_expression")
|
||||
private String cronExpression;
|
||||
|
||||
/**
|
||||
* Whether or not the job is active and available to be scheduled.
|
||||
*/
|
||||
@Column(name = "active")
|
||||
private boolean active;
|
||||
|
||||
/**
|
||||
* Whether or not the job should be re-tried in an recovery of fail over situation.
|
||||
*/
|
||||
@Column(name = "recovery")
|
||||
private boolean recovery;
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.sheldan.abstracto.scheduling.service;
|
||||
|
||||
import dev.sheldan.abstracto.scheduling.model.JobParameters;
|
||||
import dev.sheldan.abstracto.scheduling.model.database.SchedulerJob;
|
||||
import org.quartz.JobDataMap;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -59,14 +59,14 @@ public interface SchedulerService {
|
||||
boolean executeJob(SchedulerJob job);
|
||||
|
||||
/**
|
||||
* Executes the job identified by name and group with the given {@link JobDataMap} as parameters on the given {@link Date}
|
||||
* Executes the job identified by name and group with the given {@link JobParameters} as parameters on the given {@link Date}
|
||||
* @param name The name of the job to execute
|
||||
* @param group The group of the job to execute
|
||||
* @param dataMap The {@link JobDataMap} made available to the group
|
||||
* @param dataMap The {@link JobParameters} made available to the group
|
||||
* @param date The {@link Date} at which the job should be execute at.
|
||||
* @return The trigger key which triggers the job at the given date
|
||||
*/
|
||||
String executeJobWithParametersOnce(String name, String group, JobDataMap dataMap, Date date);
|
||||
String executeJobWithParametersOnce(String name, String group, JobParameters dataMap, Date date);
|
||||
|
||||
/**
|
||||
* Stops the trigger identified by the trigger key.
|
||||
|
||||
Reference in New Issue
Block a user