Skip to content

Commit

Permalink
feat : adds sample job scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Feb 19, 2024
1 parent 977b83c commit d0763ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
"projectName": "boot-graphql-webflux",
"args": "",
"envFile": "${workspaceFolder}/.env"
},
{
"type": "java",
"name": "Spring Boot-Application<boot-shedlock-sample>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "com.learning.shedlock.Application",
"projectName": "boot-shedlock-sample",
"args": "--spring.profiles.active=local",
"envFile": "${workspaceFolder}/.env"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.learning.shedlock.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class Initializer implements CommandLineRunner {
public class Initializer {

private final ApplicationProperties properties;

@Override
public void run(String... args) {
log.info("Running Initializer.....");
@Scheduled(cron = "0 */1 * * * *")
@SchedulerLock(name = "lockedTask", lockAtMostFor = "PT5S", lockAtLeastFor = "PT2S")
public void lockedTask() {
// code for task to be performed
log.info("Scheduler Job triggered");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE lockProvider (
CREATE TABLE shedlock (
name VARCHAR(64),
lock_until TIMESTAMP(3) NULL,
locked_at TIMESTAMP(3) NULL,
Expand Down

0 comments on commit d0763ad

Please sign in to comment.