Search code examples
windowsgrailsscheduled-tasks

@Scheduled tasks failing to execute


I have grails 4.0.2 running on Windows 7. Following the most basic section of the @Scheduled guide found here:

https://guides.grails.org/grails-scheduled/guide/index.html

I'm not receiving any output to console. I even attempted to use their provided project. Here is the relevant code:

In grails-app/conf/logback.groovy

logger('demo', INFO, ['STDOUT'], false)

In grails-app/services/demo/HelloWorldJobService.groovy

package demo

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.scheduling.annotation.Scheduled

import java.text.SimpleDateFormat

@Slf4j 
@CompileStatic 
class HelloWorldJobService {

    static lazyInit = false 

    @Scheduled(fixedDelay = 10000L) 
    void executeEveryTen() {
        log.info "Simple Job every 10 seconds :{}", new SimpleDateFormat("dd/M/yyyy hh:mm:ss").format(new Date())
    }

    @Scheduled(fixedDelay = 45000L, initialDelay = 5000L) 
    void executeEveryFourtyFive() {
        log.info "Simple Job every 45 seconds :{}", new SimpleDateFormat("dd/M/yyyy hh:mm:ss").format(new Date())
    }
}

Since this is intended to be a simple guide, I'm assuming there's a configuration error on my end, but I haven't been able to find it yet.


Solution

  • I believe the guide is incorrect - spring-scheduling will not work without @EnableScheduling on the app or a scheduler configured -

    https://spring.io/guides/gs/scheduling-tasks/#_enable_scheduling