Skip to content

Commit

Permalink
fix: 스케줄러 잡 실행시 스프링 컨텍스트 내에서 찾도록 변경 (#87)
Browse files Browse the repository at this point in the history
* fix: Job 실행시 spring context에 존재하는 빈으로 등록된 잡 사용하도록 변경

* fix: 임시 배포

* feat: 6시간 단위 스케줄링으로 조정

* chore: 불필요한 코드 제거
  • Loading branch information
songyi00 authored Nov 5, 2024
1 parent 6c55bf2 commit 0305254
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches:
- main
- develop
- fix/#82-fix-mission-status

jobs:
build-and-push:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Component
@Configuration
public class SchedulerConfig {
private final Scheduler scheduler;
private final List<CustomAutomationJob> jobList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.nexters.goalpanzi.schedule;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;

@Configuration
public class SchedulerFactoryConfig {
Expand All @@ -21,12 +23,21 @@ public ThreadPoolTaskExecutor executor() {
return executor;
}

@Bean
public SpringBeanJobFactory jobFactory(ApplicationContext ctx) {
SpringBeanJobFactory springBeanJobFactory = new SpringBeanJobFactory();
springBeanJobFactory.setApplicationContext(ctx);
return springBeanJobFactory;
}

@Bean
public SchedulerFactoryBean schedulerFactory(
@Qualifier(SCHEDULER_THREAD_POOL_EXECUTOR) ThreadPoolTaskExecutor threadPoolTaskExecutor
@Qualifier(SCHEDULER_THREAD_POOL_EXECUTOR) ThreadPoolTaskExecutor threadPoolTaskExecutor,
SpringBeanJobFactory jobFactory
) {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setTaskExecutor(threadPoolTaskExecutor);
factory.setJobFactory(jobFactory);
return factory;
}
}

0 comments on commit 0305254

Please sign in to comment.