Skip to content

Commit

Permalink
Created Job interface to stereotype all job classes
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorKhan committed Apr 13, 2024
1 parent 2094b71 commit 99e698c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.lucoenergia.conluz.infrastructure.admin.supply.sync;

import org.lucoenergia.conluz.domain.admin.supply.sync.DatadisSuppliesSyncService;
import org.lucoenergia.conluz.infrastructure.shared.job.Job;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class DatadisSuppliesSyncDailyJob {
public class DatadisSuppliesSyncDailyJob implements Job {

private static final Logger LOGGER = LoggerFactory.getLogger(DatadisSuppliesSyncDailyJob.class);

Expand All @@ -26,8 +27,9 @@ public DatadisSuppliesSyncDailyJob(DatadisSuppliesSyncService datadisSuppliesSyn
* * (every month)
* ? (any day of the week)
*/
@Override
@Scheduled(cron = "0 0 2 * * ?")
public void everyFiveSeconds() {
public void run() {
LOGGER.info("Datadis supplies daily sync started...");
datadisSuppliesSyncService.synchronizeSupplies();
LOGGER.info("...finished Datadis supplies daily sync.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.lucoenergia.conluz.infrastructure.consumption.datadis.sync;

import org.lucoenergia.conluz.domain.consumption.datadis.sync.DatadisConsumptionSyncService;
import org.lucoenergia.conluz.infrastructure.shared.job.Job;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class DatadisConsumptionsSyncDailyJob {
public class DatadisConsumptionsSyncDailyJob implements Job {

private static final Logger LOGGER = LoggerFactory.getLogger(DatadisConsumptionsSyncDailyJob.class);

Expand All @@ -26,8 +27,9 @@ public DatadisConsumptionsSyncDailyJob(DatadisConsumptionSyncService datadisCons
* * (every month)
* ? (any day of the week)
*/
@Override
@Scheduled(cron = "0 0 4 * * ?")
public void everyFiveSeconds() {
public void run() {
LOGGER.info("Datadis consumption daily sync started...");
datadisConsumptionSyncService.synchronizeConsumptions();
LOGGER.info("...finished Datadis consumption daily sync.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.lucoenergia.conluz.infrastructure.consumption.shelly.aggregate;

import org.lucoenergia.conluz.infrastructure.shared.job.Job;
import org.lucoenergia.conluz.infrastructure.shared.time.TimeConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -9,7 +10,7 @@
import java.time.OffsetDateTime;

@Component
public class ShellyConsumptionsHourlyAggregatorJob {
public class ShellyConsumptionsHourlyAggregatorJob implements Job {

private static final Logger LOGGER = LoggerFactory.getLogger(ShellyConsumptionsHourlyAggregatorJob.class);

Expand All @@ -30,8 +31,9 @@ public ShellyConsumptionsHourlyAggregatorJob(ShellyConsumptionsHourlyAggregator
* The fifth field is for the month. A '*' means "every month".
* The sixth and final field is for the day of the week. A '*' means "every day of the week".
*/
@Override
@Scheduled(cron = "0 0 * * * *")
public void everyFiveSeconds() {
public void run() {
LOGGER.info("Shelly consumption hourly aggregation started...");

// We perform the aggregation hourly between now and 5 hours before. This way, could have at least five retries
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.lucoenergia.conluz.infrastructure.price.sync;

import org.lucoenergia.conluz.domain.price.sync.SyncDailyPricesService;
import org.lucoenergia.conluz.infrastructure.shared.job.Job;
import org.lucoenergia.conluz.infrastructure.shared.time.TimeConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -10,7 +11,7 @@
import java.time.OffsetDateTime;

@Component
public class SyncDailyPricesJob {
public class SyncDailyPricesJob implements Job {

private static final Logger LOGGER = LoggerFactory.getLogger(SyncDailyPricesJob.class);

Expand All @@ -31,6 +32,7 @@ public SyncDailyPricesJob(TimeConfiguration timeConfiguration, SyncDailyPricesSe
* The fifth field is for the month. A '*' means "every month".
* The sixth and final field is for the day of the week. A '*' means "every day of the week".
*/
@Override
@Scheduled(cron = "0 6 * * * *")
public void run() {
LOGGER.info("OMIE prices daily retrieval started...");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.lucoenergia.conluz.infrastructure.production.huawei.sync;

import org.lucoenergia.conluz.domain.production.huawei.sync.SyncHuaweiProductionService;
import org.lucoenergia.conluz.infrastructure.shared.job.Job;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class SyncHuaweiHourlyProductionJob {
public class SyncHuaweiHourlyProductionJob implements Job {

private static final Logger LOGGER = LoggerFactory.getLogger(SyncHuaweiHourlyProductionJob.class);

Expand All @@ -20,6 +21,7 @@ public SyncHuaweiHourlyProductionJob(SyncHuaweiProductionService syncHuaweiProdu
/**
* This method starts the Huawei hourly production sync process every hour at 5 minutes past the hour.
*/
@Override
@Scheduled(cron = "0 5 * * * *")
public void run() {
LOGGER.info("Huawei hourly production sync started...");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.lucoenergia.conluz.infrastructure.production.huawei.sync;

import org.lucoenergia.conluz.domain.production.huawei.sync.SyncHuaweiProductionService;
import org.lucoenergia.conluz.infrastructure.shared.job.Job;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class SyncHuaweiRealTimeProductionJob {
public class SyncHuaweiRealTimeProductionJob implements Job {

private static final Logger LOGGER = LoggerFactory.getLogger(SyncHuaweiRealTimeProductionJob.class);

Expand All @@ -21,6 +22,7 @@ public SyncHuaweiRealTimeProductionJob(SyncHuaweiProductionService syncHuaweiPro
* This method is a scheduled task that is executed every 5 minutes.
* It synchronizes the real-time production data from Huawei energy stations.
*/
@Override
@Scheduled(cron = "0 */5 * * * *")
public void run() {
LOGGER.info("Huawei real-time production sync started...");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.lucoenergia.conluz.infrastructure.shared.job;

public interface Job {

void run();
}

0 comments on commit 99e698c

Please sign in to comment.