-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Billing-Wise/dev
[release] 1.0.2
- Loading branch information
Showing
38 changed files
with
5,843 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/site/billingwise/batch/server_batch/batch/controller/BatchJobController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package site.billingwise.batch.server_batch.batch.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.JobParameters; | ||
import org.springframework.batch.core.JobParametersBuilder; | ||
import org.springframework.batch.core.launch.JobLauncher; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequestMapping("/api/batch") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class BatchJobController { | ||
|
||
private final JobLauncher jobLauncher; | ||
private final Job jdbcGenerateInvoiceJob; | ||
private final Job invoiceProcessingJob; | ||
private final Job weeklyInvoiceStatisticsJob; | ||
private final Job monthlyInvoiceStatisticsJob; | ||
|
||
@PostMapping("/generate-invoice") | ||
public String runJdbcGenerateInvoiceJob() { | ||
return launchJob(jdbcGenerateInvoiceJob, "jdbcInvoice"); | ||
} | ||
|
||
@PostMapping("/process-invoice") | ||
public String runInvoiceProcessingJob() { | ||
return launchJob(invoiceProcessingJob, "InvoiceProcessingJob"); | ||
} | ||
|
||
@PostMapping("/weekly-statistics") | ||
public String runWeeklyStatisticsJob() { | ||
return launchJob(weeklyInvoiceStatisticsJob, "weeklyInvoiceStatisticsJob"); | ||
} | ||
|
||
@PostMapping("/monthly-statistics") | ||
public String runMonthlyStatisticsJob() { | ||
return launchJob(monthlyInvoiceStatisticsJob, "monthlyInvoiceStatisticsJob"); | ||
} | ||
|
||
|
||
|
||
private String launchJob(Job job, String jobName) { | ||
String uuid = UUID.randomUUID().toString(); | ||
JobParameters jobParameters = new JobParametersBuilder() | ||
.addLong(jobName, System.currentTimeMillis()) | ||
.addString("UUID", uuid) | ||
.toJobParameters(); | ||
try { | ||
jobLauncher.run(job, jobParameters); | ||
return "Job " + jobName + " submitted successfully. UUID: " + uuid; | ||
} catch (Exception e) { | ||
log.error("Error occurred while starting job: {} with UUID: {}. Error: {}", jobName, uuid, e.getMessage()); | ||
return "Error occurred while starting job: " + jobName + ". UUID: " + uuid; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.