Skip to content

Commit

Permalink
Merge pull request #102 from Team-MindWay/101-in-progress-not-event-i…
Browse files Browse the repository at this point in the history
…n-progress-to-event-change-scheduleer

🔀 :: Pending인 이벤트를 Now로 전환시키는 스케줄러 구현
  • Loading branch information
Umjiseung authored Apr 21, 2024
2 parents db22255 + 9231ad7 commit e67a6cf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.mindway.server.v2.domain.event.scheduler;

import com.mindway.server.v2.domain.event.service.ChangeNowToPastService;
import com.mindway.server.v2.domain.event.service.ChangePendingToNowService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;

@RequiredArgsConstructor
public class EventScheduler {

private final ChangeNowToPastService changeNowToPastService;
private final ChangePendingToNowService changePendingToNowService;

@Scheduled(cron = "0 0 0 * *", zone = "Asia/Seoul")
public void changeNowToPast() {
changeNowToPastService.execute();
}

@Scheduled(cron = "0 0 0 * *", zone = "Asia/Seoul")
public void changePendingToNow() {
changePendingToNowService.execute();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.mindway.server.v2.domain.event.service;

public interface ChangePendingToNowService {
void execute();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.mindway.server.v2.domain.event.service.impl;

import com.mindway.server.v2.domain.event.entity.Event;
import com.mindway.server.v2.domain.event.entity.Status;
import com.mindway.server.v2.domain.event.repository.EventRepository;
import com.mindway.server.v2.domain.event.service.ChangePendingToNowService;
import com.mindway.server.v2.global.annotation.ServiceWithTransaction;
import lombok.RequiredArgsConstructor;

import java.time.LocalDate;
import java.util.List;
import java.util.Objects;


@ServiceWithTransaction
@RequiredArgsConstructor
public class ChangePendingToNowServiceImpl implements ChangePendingToNowService {

private final EventRepository eventRepository;

public void execute() {
List<Event> pendingEvents = eventRepository.findByStatus(Status.PENDING);

for (Event event: pendingEvents) {
if (Objects.equals(event.getStarted_at(), LocalDate.now())) {
saveChangeNow(event);
}
}
}

private void saveChangeNow(Event event) {
event.changeStatus(Status.NOW);

eventRepository.save(event);
}
}

0 comments on commit e67a6cf

Please sign in to comment.