Files
apkt-data-309/src/main/java/id/co/iconpln/apkt/data309/schedule/MyScheduledBean.java
Eko Haryadi 091106abf4 feat: Implement RekapGarduDistribusi resource and related DTOs
- Added RekapGarduDistribusiResource for handling data retrieval and synchronization.
- Created RekapGarduDistribusiDTO to represent the data structure for distribution records.
- Developed RekapGarduDistribusiResponse to encapsulate the response from the external API.
- Introduced RekapGarduDistribusi entity to map to the database table.
- Implemented GarduService for synchronizing data with external API.
- Enhanced error handling and logging during data synchronization.
2025-08-26 16:20:27 +07:00

50 lines
1.8 KiB
Java

package id.co.iconpln.apkt.data309.schedule;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import io.quarkus.scheduler.Scheduled;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class MyScheduledBean {
// every month at day 7 on 23.59
@Scheduled(cron = "0 59 23 7 * ?")
void scheduleCron() throws Exception {
HttpClient client = HttpClient.newHttpClient();
// Username and password for basic authentication
// String username = "apkt";
// String password = "apkt@54321";
// Combine username and password for basic authentication
// String auth = username + ":" + password;
// Encode the combined string with Base64
// String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
// Add the Authorization header with Basic auth to the request
HttpRequest request = HttpRequest.newBuilder()
// .header("Authorization", "Basic " + encodedAuth)
.uri(URI.create("http://10.14.212.9:32184/data309/sinkron"))
.GET()
.build();
client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Scheduled task executed successfully");
}
@Scheduled(cron = "0 59 23 1 * ?")
void scheduleCronGardu() throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://10.14.212.9:32184/rekapGarduDistribusi/sinkron"))
.GET()
.build();
client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Scheduled Rekap Gardu task executed successfully");
}
}