Skip to content

Commit a4aa8ab

Browse files
feat: shedlock example (#36)
1 parent 4b0799d commit a4aa8ab

File tree

5 files changed

+180
-1
lines changed

5 files changed

+180
-1
lines changed

jdbc/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<artifactId>ydb-jdbc-driver</artifactId>
3333
<version>${ydb.jdbc.version}</version>
3434
</dependency>
35-
3635
<dependency>
3736
<groupId>org.slf4j</groupId>
3837
<artifactId>jul-to-slf4j</artifactId>
@@ -51,6 +50,7 @@
5150
<module>spring-data-jpa</module>
5251
<module>spring-flyway-app</module>
5352
<module>spring-liquibase-app</module>
53+
<module>shedlock</module>
5454
</modules>
5555
</profile>
5656
</profiles>

jdbc/shedlock/pom.xml

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>tech.ydb.jdbc.examples</groupId>
5+
<artifactId>ydb-jdbc-examples</artifactId>
6+
<version>1.1.0-SNAPSHOT</version>
7+
</parent>
8+
9+
<version>0.1.0</version>
10+
<name>Spring ShedLock Example</name>
11+
<artifactId>shedlock-ydb</artifactId>
12+
<properties>
13+
<maven.compiler.release>17</maven.compiler.release>
14+
<kotlin.version>1.9.22</kotlin.version>
15+
<shed.lock.ydb>0.1.0</shed.lock.ydb>
16+
<spring.boot.version>3.1.2</spring.boot.version>
17+
</properties>
18+
<dependencyManagement>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-dependencies</artifactId>
23+
<version>3.2.1</version>
24+
<scope>import</scope>
25+
<type>pom</type>
26+
</dependency>
27+
</dependencies>
28+
</dependencyManagement>
29+
<dependencies>
30+
<dependency>
31+
<groupId>net.javacrumbs.shedlock</groupId>
32+
<artifactId>shedlock-spring</artifactId>
33+
<version>4.27.0</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-web</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-autoconfigure</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-aop</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-starter-jdbc</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.jetbrains.kotlin</groupId>
53+
<artifactId>kotlin-reflect</artifactId>
54+
<version>${kotlin.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.jetbrains.kotlin</groupId>
58+
<artifactId>kotlin-stdlib</artifactId>
59+
<version>${kotlin.version}</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>tech.ydb.dialects</groupId>
63+
<artifactId>shedlock-ydb</artifactId>
64+
<version>${shed.lock.ydb}</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>tech.ydb.jdbc</groupId>
68+
<artifactId>ydb-jdbc-driver</artifactId>
69+
</dependency>
70+
</dependencies>
71+
<build>
72+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
73+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
74+
<plugins>
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-surefire-plugin</artifactId>
78+
<configuration>
79+
<environmentVariables>
80+
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
81+
</environmentVariables>
82+
</configuration>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.springframework.boot</groupId>
86+
<artifactId>spring-boot-maven-plugin</artifactId>
87+
<version>${spring.boot.version}</version>
88+
</plugin>
89+
<plugin>
90+
<groupId>org.jetbrains.kotlin</groupId>
91+
<artifactId>kotlin-maven-plugin</artifactId>
92+
<version>${kotlin.version}</version>
93+
<executions>
94+
<execution>
95+
<id>compile</id>
96+
<phase>compile</phase>
97+
<goals>
98+
<goal>compile</goal>
99+
</goals>
100+
</execution>
101+
<execution>
102+
<id>test-compile</id>
103+
<goals>
104+
<goal>test-compile</goal>
105+
</goals>
106+
</execution>
107+
</executions>
108+
<configuration>
109+
<args>
110+
<arg>-Xjsr305=strict</arg>
111+
</args>
112+
<compilerPlugins>
113+
<plugin>spring</plugin>
114+
<plugin>jpa</plugin>
115+
</compilerPlugins>
116+
</configuration>
117+
<dependencies>
118+
<dependency>
119+
<groupId>org.jetbrains.kotlin</groupId>
120+
<artifactId>kotlin-maven-allopen</artifactId>
121+
<version>${kotlin.version}</version>
122+
</dependency>
123+
<dependency>
124+
<groupId>org.jetbrains.kotlin</groupId>
125+
<artifactId>kotlin-maven-noarg</artifactId>
126+
<version>${kotlin.version}</version>
127+
</dependency>
128+
</dependencies>
129+
</plugin>
130+
</plugins>
131+
</build>
132+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package tech.ydb.shaded.lock
2+
3+
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock
4+
import org.springframework.boot.SpringApplication
5+
import org.springframework.boot.autoconfigure.SpringBootApplication
6+
import org.springframework.scheduling.annotation.EnableScheduling
7+
8+
/**
9+
* @author Kirill Kurdyukov
10+
*/
11+
@SpringBootApplication
12+
@EnableScheduling
13+
@EnableSchedulerLock(defaultLockAtMostFor = "30s")
14+
class Application
15+
16+
fun main() {
17+
SpringApplication.run(Application::class.java)
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package tech.ydb.shaded.lock
2+
3+
import jakarta.annotation.PostConstruct
4+
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock
5+
import org.springframework.beans.factory.annotation.Autowired
6+
import org.springframework.scheduling.annotation.Scheduled
7+
import org.springframework.stereotype.Component
8+
import tech.ydb.lock.provider.YdbCoordinationServiceLockProvider
9+
10+
11+
/**
12+
* @author Kirill Kurdyukov
13+
*/
14+
@Component
15+
class JobHandler {
16+
17+
@Scheduled(cron = "* * * * * *")
18+
@SchedulerLock(name = "YDB Some Job", lockAtLeastFor = "15S", lockAtMostFor = "20S")
19+
fun awesomeJob() {
20+
for (i in 0..4) {
21+
println("Processing {$i}")
22+
23+
Thread.sleep(1_000)
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local
2+
spring.datasource.driver-class-name=tech.ydb.jdbc.YdbDriver
3+
server.port=81

0 commit comments

Comments
 (0)