Skip to content

Commit 19f0c18

Browse files
committed
Quartz Support for Job Scheduler.
1 parent 9d2659c commit 19f0c18

17 files changed

+545
-8
lines changed

pom.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<artifactId>postgresql</artifactId>
3434
<scope>runtime</scope>
3535
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-quartz</artifactId>
39+
</dependency>
3640
<dependency>
3741
<groupId>org.hibernate.orm</groupId>
3842
<artifactId>hibernate-ehcache</artifactId>
@@ -177,9 +181,14 @@
177181
</dependency>
178182
<dependency>
179183
<groupId>org.springframework.boot</groupId>
180-
<artifactId>spring-boot-docker-compose</artifactId>
181-
<scope>runtime</scope>
184+
<artifactId>spring-boot-starter-jdbc</artifactId>
182185
</dependency>
186+
187+
<!-- <dependency>-->
188+
<!-- <groupId>org.springframework.boot</groupId>-->
189+
<!-- <artifactId>spring-boot-docker-compose</artifactId>-->
190+
<!-- <scope>runtime</scope>-->
191+
<!-- </dependency>-->
183192
<dependency>
184193
<groupId>org.springframework.boot</groupId>
185194
<artifactId>spring-boot-starter-data-mongodb</artifactId>

src/main/java/org/wsd/app/bootloader/BootLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void run(String... args) throws Exception {
6565
person.setAddress(address);
6666
person.setGender(Gender.MALE);
6767

68-
personRepository.save(person);
68+
// personRepository.save(person);
6969

7070
}
7171
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) of Partha Sutradhar 2024.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
package org.wsd.app.config;
24+
25+
import org.springframework.context.annotation.Configuration;
26+
27+
@Configuration
28+
public class QuartzConfig {
29+
30+
31+
}

src/main/java/org/wsd/app/controller/AuthenticationController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@Log
2525
@RestController
2626
@RequestMapping("/api/auth")
27-
@Tag(name = "Authentication")
27+
@Tag(name = "Authentication Controller")
2828
@RequiredArgsConstructor
2929
public class AuthenticationController {
3030
private final AuthenticationService authenticationService;

src/main/java/org/wsd/app/controller/OrderController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@RestController
1212
@RequiredArgsConstructor
13-
@Tag(name = "Order")
13+
@Tag(name = "Order Controller")
1414
@SecurityRequirement(name = "BEARER_TOKEN")
1515
@RequestMapping("/api/orders")
1616
public class OrderController {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) of Partha Sutradhar 2024.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
package org.wsd.app.controller;
24+
25+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
26+
import io.swagger.v3.oas.annotations.tags.Tag;
27+
import lombok.RequiredArgsConstructor;
28+
import org.springframework.web.bind.annotation.PathVariable;
29+
import org.springframework.web.bind.annotation.PostMapping;
30+
import org.springframework.web.bind.annotation.RequestMapping;
31+
import org.springframework.web.bind.annotation.RestController;
32+
import org.wsd.app.quartz.ExecutionTimer;
33+
import org.wsd.app.quartz.SchedulerService;
34+
import org.wsd.app.quartz.TaskRunner;
35+
36+
@RestController
37+
@Tag(name = "Scheduler Controller")
38+
@RequiredArgsConstructor
39+
@SecurityRequirement(name = "BEARER_TOKEN")
40+
@RequestMapping("/api/schedulers")
41+
public class SchedulerController {
42+
private final SchedulerService schedulerService;
43+
@PostMapping("/{id}")
44+
public void execute(@PathVariable("id") int id) {
45+
ExecutionTimer executionTimer = new ExecutionTimer();
46+
executionTimer.setId(id);
47+
executionTimer.setMaxExecution(5);
48+
executionTimer.setRepeatedInterval(5000);
49+
// executionTimer.setCronExpression("0/5 * * * * ? *");
50+
executionTimer.setRunForever(false);
51+
executionTimer.setInitialDelay(5000);
52+
executionTimer.setData("Execution Completed!!");
53+
schedulerService.schedule(TaskRunner.class, executionTimer);
54+
}
55+
}

src/main/java/org/wsd/app/controller/TwoFactorAuthController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
@RestController
1717
@RequestMapping("/api/auth")
1818
@RequiredArgsConstructor
19-
@Tag(name = "Two Factor Authentication")
19+
@Tag(name = "Two Factor Authentication Controller")
2020
@SecurityRequirement(name = "BEARER_TOKEN")
2121
public class TwoFactorAuthController {
2222
private final TwoFactorService twoFactorService;
23+
2324
@Operation(description = "Two Factor Authentication", summary = "Endpoint for two factor authentication service enable and disable.")
2425
@GetMapping("/2Fa/configure")
2526
public Payload<TwoFactorResponse> twoFactorSetup(TwoFactorRequest request) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) of Partha Sutradhar 2024.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
package org.wsd.app.quartz;
24+
25+
import lombok.Data;
26+
import lombok.ToString;
27+
28+
import java.io.Serializable;
29+
30+
@ToString
31+
@Data
32+
public class ExecutionTimer implements Serializable {
33+
private int id;
34+
private int maxExecution;
35+
private int remainingExecution;
36+
private long repeatedInterval;
37+
private boolean runForever;
38+
private long initialDelay;
39+
private String cronExpression;
40+
private String data;
41+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) of Partha Sutradhar 2024.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
package org.wsd.app.quartz;
24+
25+
26+
import jakarta.persistence.*;
27+
import lombok.Data;
28+
import org.hibernate.annotations.Generated;
29+
30+
@Entity
31+
@Data
32+
@Table(name = "schedule_task")
33+
public class ScheduleTask {
34+
@Id
35+
@GeneratedValue(strategy = GenerationType.AUTO)
36+
private Long id;
37+
private String jobTask;
38+
private String jobGroup;
39+
private String jobStatus;
40+
private String jobClass;
41+
private String cronExpression;
42+
private String description;
43+
private String interfaceName;
44+
private Long repeatTime;
45+
private Boolean cronJob;
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) of Partha Sutradhar 2024.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
package org.wsd.app.quartz;
24+
25+
import org.quartz.spi.TriggerFiredBundle;
26+
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
27+
import org.springframework.context.ApplicationContext;
28+
import org.springframework.context.ApplicationContextAware;
29+
import org.springframework.scheduling.quartz.SpringBeanJobFactory;
30+
31+
public class SchedulerJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {
32+
33+
private AutowireCapableBeanFactory beanFactory;
34+
35+
@Override
36+
public void setApplicationContext(final ApplicationContext context) {
37+
beanFactory = context.getAutowireCapableBeanFactory();
38+
}
39+
40+
@Override
41+
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
42+
final Object job = super.createJobInstance(bundle);
43+
beanFactory.autowireBean(job);
44+
return job;
45+
}
46+
}

0 commit comments

Comments
 (0)