繁体   English   中英

Micronaut @Scheduled 作业未运行

[英]Micronaut @Scheduled job not running

我正在使用 groovy 和 gradle 开发现有的 micronaut 应用程序,它有一个调度程序,预计每 1 分钟运行一次。 不知何故,调度程序根本没有运行,应用程序也没有抛出任何错误(只是保持沉默)。 我看不出有任何不应该这样做的理由,但我是 micronaut 的新手,我可能会遗漏一些东西。 任何指针表示赞赏,长期以来一直困扰着这个问题。 这是调度程序 class。

 @CompileStatic
 @Singleton
 @Requires(notEnv = "test")
 class CsmTestJob {

 private final CsmTestJobExecutor csmTestJobExecutor

 CsmTestJob(CsmTestJobExecutor csmTestJobExecutor) {
    this.csmTestJobExecutor = csmTestJobExecutor
 }

 @Scheduled(fixedDelay = '${feature.job.execute}')
 void executeCsmTests() {
    csmTestJobExecutor.executeCsmTests()
 }
}

这是application.yml文件

micronaut:
  application:
    name: csm
  server:
    port: 8080
    host: 127.0.0.1

feature: 
  job:
    execute: "1m"

有关于删除 static 编译和删除动态计划值的评论,但我认为其中任何一个都可能无关紧要。 问题中显示的代码不足,无法确定,但我怀疑您的代码可能使用了错误的@Singleton注释。

请参阅https://github.com/jeffbrown/nilambersinghscheduledjob上的项目。

https://github.com/jeffbrown/nilambersinghscheduledjob/blob/c7892b556c8564d34d1b3265f53c0f81904150aa/src/main/resources/application.yml

micronaut:
  application:
    name: nilambersinghscheduledjob
feature:
  job:
    execute: "1m"

https://github.com/jeffbrown/nilambersinghscheduledjob/blob/c7892b556c8564d34d1b3265f53c0f81904150aa/src/main/groovy/com/example/CsmTestJobFAE70B7AF1

package com.example

import groovy.transform.CompileStatic
import io.micronaut.context.annotation.Requires
import io.micronaut.scheduling.annotation.Scheduled
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import javax.inject.Singleton

@CompileStatic
@Singleton
@Requires(notEnv = "test")
class CsmTestJob {

    private static final Logger log = LoggerFactory.getLogger(CsmTestJob)
    @Scheduled(fixedDelay = '${feature.job.execute}')
    void executeCsmTests() {
        log.debug "CSM Test Job Is Running"
    }
}

这一切都很好。

不久前我遇到了一个类似的问题,结果发现我在 class 上的其他注释之一以某种方式干扰并阻止了调度程序运行。

我会尝试删除 CompileStatic 并将时间表硬编码为直接字符串文字。

Also make sure you are importing javax.inject.Singleton because otherwise your reference to Singleton will pick the groovy default groovy.lang.Singleton which will break micronaut mechanics.

最后要尝试的是打开调试日志并阅读 micronaut 打印的大量信息。 就我而言,我可以从调试日志中看到 bean 初始化存在问题。

我意识到这不是一个直接的解决方案,但认为给出一些潜在的指示总比没有好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM