本文介绍了Akka石英调度程序不会触发作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的游戏项目中使用。
我创建了两个akka演员,并为演员添加了配置:

I try to use this akka-quartz-scheduler in my play project.I created two akka actors, added configuration for actors:

akka {
  quartz {
    schedules {
      HELLO_ACTOR {
        description = "A cron job that fires off every 10 seconds"
        expression = "0/10 0 0 ? * * *"
      }
      CLEANUP_ACTOR {
        description = "A cron job that fires off every 10 seconds"
        expression = "0/10 0 0 ? * * *"
      }
    }
  }
}

我创建了模块,并在调度器和绑定调度器的地方添加了调度器:

I created module and add scheduler where i bind actors and scheduler:

protected void configure() {
        bindActor(HelloActor.class, HelloActor.NAME);
        bindActor(CleanupRunner.class, CleanupRunner.NAME);
        bind(QuartzSchedulerHelper.class).asEagerSingleton();
        bind(QuartzSchedulerExtension.class).toProvider(SchedulerJobInitializer.class);
    }


    private static class SchedulerJobInitializer implements Provider<QuartzSchedulerExtension> {
        private final QuartzSchedulerExtension quartzSchedulerExtension;

        @Inject
        public SchedulerJobInitializer(ActorSystem actorSystem) {
            this.quartzSchedulerExtension = new QuartzSchedulerExtension((ExtendedActorSystem) actorSystem);
        }

        @Override
        public QuartzSchedulerExtension get() {
            return quartzSchedulerExtension;
        }
    }

应用程序启动时,我在日志中看到参与者已添加到调度程序中:

When application starts, I see in the log that actors were added to scheduler:

2018-07-06 11:51:44,947 [INFO] from org.quartz.impl.DirectSchedulerFactory in play-dev-mode-akka.actor.default-dispatcher-2 - Quartz scheduler 'QuartzScheduler~application

2018-07-06 11:51:44,947 [INFO] from org.quartz.impl.DirectSchedulerFactory in play-dev-mode-akka.actor.default-dispatcher-2 - Quartz scheduler version: 2.2.3

2018-07-06 11:51:44,950 [INFO] from org.quartz.core.QuartzScheduler in play-dev-mode-akka.actor.default-dispatcher-2 - Scheduler QuartzScheduler~application_$_application started.

2018-07-06 11:51:44,974 [INFO] from com.typesafe.akka.extension.quartz.QuartzSchedulerExtension in application-akka.actor.default-dispatcher-2 - Setting up scheduled job 'HELLO_ACTOR', with 'com.typesafe.akka.extension.quartz.QuartzCronSchedule@6a6c7b3b'

2018-07-06 11:51:45,005 [INFO] from com.typesafe.akka.extension.quartz.QuartzSchedulerExtension in application-akka.actor.default-dispatcher-2 - Setting up scheduled job 'CLEANUP_ACTOR', with 'com.typesafe.akka.extension.quartz.QuartzCronSchedule@2c32247d'

应该每10秒钟触发一次。任何不起作用的原因,或者我应该在什么地方添加?

Acotrs should be triggered every 10 seconds. Any reason why this do not work, or what should I add and where?

这里是。

推荐答案

您的日志摘要并不表示您的演员已在调度程序中注册。它显示的是Quartz作业已成功调度:在您的配置中, akka.quartz.schedules.HELLO_ACTOR akka.quartz.schedules。 CLEANUP_ACTOR 工作,而不是演员,尽管您已将其命名。 (我建议重命名这些作业以避免混淆。)

Your log snippet does not indicate that your actors are registered with the scheduler. What it does show is that the Quartz jobs are successfully scheduled: in your configuration, akka.quartz.schedules.HELLO_ACTOR and akka.quartz.schedules.CLEANUP_ACTOR are jobs, not actors, despite what you've named them. (I recommend renaming those jobs to avoid confusion.)

考虑您的,看来您的演员不是已向调度程序注册:

Considering your QuartzSchedulerHelper, it doesn't appear that your actors are registered with the scheduler:

List<String> actors = Arrays.asList(HelloActor.NAME, CleanupRunner.NAME);
for (String name : actors) {
  ActorRef actor = registry.actorFor(name);
  schedule(quartzSchedulerExtension, actor, name, RandomStringUtils.randomAlphabetic(10));
}

actorFor 演员路径作为参数。您要传递给该方法的是演员的名字。使用actor路径:

actorFor takes an actor path as an argument. What you're passing to that method is the actor's name. Use the actor path:

String actorPath = "/user/" + name
ActorRef actor = registry.actorFor(actorPath)

您可能还想尝试以下actor路径:

You might also want to try the following actor path:

String actorPath = "akka://application/user/" + name

这篇关于Akka石英调度程序不会触发作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:54