Skip to content

Commit

Permalink
chore: last_message_id job scheuling
Browse files Browse the repository at this point in the history
  • Loading branch information
psychology50 committed Nov 7, 2024
1 parent 366a1d7 commit 3a38547
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Slf4j
@Component
@RequiredArgsConstructor
public class SpendingNotifyScheduler {
private final JobLauncher jobLauncher;
private final Job dailyNotificationJob;
private final Job monthlyNotificationJob;
private final Job lastMessageIdJob;

@Scheduled(cron = "0 0 20 * * ?")
public void runDailyNotificationJob() {
Expand Down Expand Up @@ -48,4 +51,18 @@ public void runMonthlyNotificationJob() {
log.error("Failed to run monthlyNotificationJob", e);
}
}

@Scheduled(fixedRate = 30, timeUnit = TimeUnit.MINUTES)
public void runLastMessageIdJob() {
JobParameters jobParameters = new JobParametersBuilder()
.addLong("time", System.currentTimeMillis())
.toJobParameters();

try {
jobLauncher.run(lastMessageIdJob, jobParameters);
} catch (JobExecutionAlreadyRunningException | JobRestartException
| JobInstanceAlreadyCompleteException | JobParametersInvalidException e) {
log.error("Failed to run lastMessageIdJob", e);
}
}
}

0 comments on commit 3a38547

Please sign in to comment.