#14 fixed the trigger rescheduling

This commit is contained in:
Fabio Formosa
2021-10-30 00:22:44 +02:00
parent c4e8eb94d6
commit 70827393b7
4 changed files with 44 additions and 6 deletions

View File

@@ -4,14 +4,14 @@
</mat-card-header>
<!-- ADD BUTTON -->
<mat-card-content *ngIf="!shouldShowTriggerConfig() && !enabledTriggerForm">
<mat-card-content *ngIf="!existsATriggerInProgress() && !enabledTriggerForm">
<button mat-fab color="primary">
<mat-icon (click)="enableTriggerForm()">add</mat-icon>
</button>
</mat-card-content>
<!-- TRIGGER DETAILS -->
<mat-card-content *ngIf="shouldShowTriggerConfig() || enabledTriggerForm">
<mat-card-content *ngIf="existsATriggerInProgress() || enabledTriggerForm">
<div fxLayout="column">
<form name="configForm" fxFlex="1 1 100%" #configForm="ngForm">
<mat-form-field >

View File

@@ -47,10 +47,12 @@ export class SchedulerConfigComponent implements OnInit {
})
}
shouldShowTriggerConfig = (): boolean => this.fetchedTriggers && this.triggerInProgress;
existsATriggerInProgress = (): boolean => this.fetchedTriggers && this.triggerInProgress;
submitConfig = () => {
this.schedulerService.updateConfig(this.config)
const schedulerServiceCall = this.existsATriggerInProgress() ? this.schedulerService.updateConfig : this.schedulerService.saveConfig;
schedulerServiceCall(this.config)
.subscribe(res => {
this.configBackup = this.config;
this.enabledTriggerForm = false;
@@ -61,5 +63,5 @@ export class SchedulerConfigComponent implements OnInit {
});
};
enableTriggerForm = () => this.enabledTriggerForm = true;
enableTriggerForm = () => this.enabledTriggerForm = true;
}

View File

@@ -37,9 +37,13 @@ export class SchedulerService {
return this.apiService.get(getBaseUrl() + '/quartz-manager/scheduler/config')
}
updateConfig = (config: Object) => {
saveConfig = (config: Object) => {
return this.apiService.post(getBaseUrl() + '/quartz-manager/triggers/mytrigger', config)
}
updateConfig = (config: Object) => {
return this.apiService.put(getBaseUrl() + '/quartz-manager/triggers/mytrigger', config)
}
}

View File

@@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.convert.ConversionService;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
@Slf4j
@RequestMapping("/quartz-manager/triggers")
@RestController
@@ -54,6 +56,7 @@ public class TriggerController {
.withRepeatCount(config.getMaxCount() - 1)
.withMisfireHandlingInstructionNextWithRemainingCount()
)
.withIdentity(name)
.build();
// Optional<TriggerKey> optionalTriggerKey = schedulerService.getTriggerByKey(name);
@@ -68,5 +71,34 @@ public class TriggerController {
return newTriggerDTO;
}
@PutMapping("/{name}")
public TriggerDTO rescheduleTrigger(@PathVariable String name, @RequestBody SchedulerConfigParam config) throws SchedulerException, ClassNotFoundException {
log.info("TRIGGER - RESCHEDULE trigger {}", config);
int intervalInMills = SchedulerService.fromTriggerPerDayToMillsInterval(config.getTriggerPerDay());
Optional<TriggerKey> optionalTriggerKey = schedulerService.getTriggerByKey(name);
TriggerKey triggerKey = optionalTriggerKey.orElse(TriggerKey.triggerKey(name));
Trigger trigger = scheduler.getTrigger(triggerKey);
Trigger newTrigger = TriggerBuilder.newTrigger()
.withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMilliseconds(intervalInMills)
.withRepeatCount(config.getMaxCount() - 1)
.withMisfireHandlingInstructionNextWithRemainingCount()
)
.forJob(trigger.getJobKey().getName())
.withIdentity(name)
.build();
// scheduler.scheduleJob(jobDetail, newTrigger);
scheduler.rescheduleJob(triggerKey, newTrigger);
TriggerDTO newTriggerDTO = conversionService.convert(newTrigger, TriggerDTO.class);
log.info("Rescheduled new trigger {}", newTriggerDTO);
return newTriggerDTO;
}
}