enragedginger / akka-quartz-scheduler Goto Github PK
View Code? Open in Web Editor NEWQuartz Extension and utilities for cron-style scheduling in Akka
License: Other
Quartz Extension and utilities for cron-style scheduling in Akka
License: Other
because I can't upgrade to scala 2.12 yet due to other constraints
Is it possible to schedule jobs which will be executed only once after a particular amount of time? Or schedule jobs which for which the time hasn't been specified in a strict configuration?
Hello,
In my projects I am currently using akka-quartz.
I would love to have all the benefits you are describing (especially the singleton-ity).
But I need to dynamically add jobs with custom schedules.
E.g. a message like this:
case OrderWithExpiry(order: Order, goodTill: Long) => {
enqueueOrder(payload)
val dt = new DateTime(goodTill)
val cronString = s"${dt.getSecondOfMinute} ${dt.getMinuteOfHour} ${dt.getHourOfDay} ${dt.getDayOfMonth} ${dt.getMonthOfYear} ? ${dt.getYear}"
quartz ! AddCronSchedule(self, cronString, ExpireOrder(order), false)
}
IMHO a quite basic use case is that some messages received by the system contain the definition of the cron schedule.
From what I understand, you explicitly ban this scenario - but maybe there is another way I could achieve my results assuming your approach? Rewriting textfile configuration would be very ineffective.
Best,
Jacek
So we are using akka-quartz-scheduler for creating csv as part of a scheduled job which kicks off very 10 minutes (timing will change once application goes to prod).
My akka config looks like following :
akka {
quartz {
schedules {
Every10Minutes {
description = "A cron job that fires off every 10 minutes"
expression = "0 0/10 * * * ?"
}
}
}
}
My scala code looks like following :
@PostConstruct
def initMessageListener(): Unit = {
val system = actorSystem
//noinspection ScalaStyle
val myManagerActor = system.actorOf(SpringExtension(system, ctx).props(senderManager), sender
Manager)
QuartzSchedulerExtension(system).schedule("Every10Minutes", myManagerActor, getCurrentDate)
}
def getCurrentDate() : String = {
val sdf = new SimpleDateFormat( "yyyy-MM-dd" );
sdf.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
sdf.format(new Date())
}
When my csv job is kicked off every 10 minutes, I am logging the message as following :
Received request to load json documents with date 2017-02-01 ",
QUERY
Assume that I started my application on Monday morning. The problem is that everything works fine till friday 11:59:59 PM. However the moment the day changes after Friday, the date parameter passed to scheduler expression never changes to Saturday's date and application continues invoke job with Friday's date.
We've observed this on two consecutive weeks and everything works fine on weekday but issue only comes after Fridays. Initially we thought it must be some random issue, however second time we realized that something is definitely not right and we have no idea why this is happening.
Need help on this and quick response is really appreciated.
Why does the rescheduleJob in QuartzSchedulerExtension only accepts ActorRef in its parameters?I prefer to use ActorSelection over ActorRef. That way if the actor dies, you can get the new path from the ActorSelection. Can you make it also accept ActorSelection?
I have a cron job scheduled with
akka.quartz.schedules {
work {
description = "Do something every hour on business hours"
expression = "0 0 8-17 ? * MON-FRI"
}
}
Instead of triggering on the hour, it's doing so at half past. It is possible that my country's timezone has something to do with this, because we are at -04:30 UTC, meaning we are displaced half an hour from what is usually expected.
Clearly I could adjust the time in the cron expression, but that would cause confusion to anyone trying to figure out when things are supposed to happen. Any help would be appreciated.
from readme:
libraryDependencies += "com.typesafe.akka" %% "akka-quartz-scheduler" % "1.2.0-akka-2.2.x"
in fact:
libraryDependencies += "com.typesafe.akka" %% "akka-quartz-scheduler_2.10" % "1.2.0-akka-2.2.x"
at least for Gradle build tool
Hello,
Just a quick question ... Don't you think that timezone should be set automaticaly to the system timezone?
I spent 2 hours figuring out why my job wasn't triggered ;)
Thanks for this great extension !
Using the scheduler in Play for Scala, I initiate the scheduler on startup like so:
val scheduler = QuartzSchedulerExtension(system) val d = scheduler.schedule("dailyproc", mainEtl, "abc", None)
Problem is that I load a table using Hibernate in the scheduler task, and when Play is reloaded due to code change, I get an error saying that classes "cannot be cast" where the class is the same. This happens because the classloaders are different.
One solution is to unload the scheduler when Play is reloaded, how can this be achieved? I could not find a method to unload the scheduler when Play is stopped/reloaded.
I tried with
scheduler.shutdown(true)
but it doesn't seem to unload the classes
Please see more details here
Is there a provision to schedule a job directly using cron expression instead of specifying the cron expression in the configuration file? As the documentation suggests, currently this is not possible, is it?
I am using akka-actor system, and send message to my actor with in specific time. akka-quartz-scheduler is amazing library for schedule chron jobs easily. But if my scheduler node goes down, how can i recover my scheduler? because my scheduling job is really important. I know, for this, we need a clustering, but is there any way using akka-quartz-scheduler for recover scheduled jobs?
Hi
I'm using to schedule daily cron jobs (run at midnight), but I want to somehow ignore the first message (when apps starts). Is there a way to add this?
Hi,
Is there a way I can configure akka-quartz-scheduler to use JDBC store instead of RAMStore. Where can i specify JDBC data source details ?
Could you please publish a Scala 2.11 and akka 2.5.x compatible version of this library? In my project I can't upgrade to Scala 2.12 yet due to a dependency on Apache Spark.
This is already on your TODO list.
I desperately need MISFIRE_INSTRUCTION_DO_NOTHING
. Can I do anything to apply it in current (1.5.0) version? trait QuartzSchedule
is sealed and class QuartzCronSchedule
is final.
Is there a way to call withMisfireHandlingInstructionDoNothing()
method on schedules?
Hi,
Should QuartzSchedulerExtension
be made thread-safe?
My understanding is that Akka extensions must normally manage thread-safety internally. At the moment, I think that it is possible for concurrent access to createSchedule
to result in a created schedule being lost if the reads, updates and writes occurring in schedules += (name.toUpperCase -> quartzSchedule)
are interleaved - causing a subsequent call to schedule
to fail.
Thanks,
-Dan
Hi, thanks for maintaining this great library!
It looks like the project has already been updated for akka 2.5.x, but there isn't a release published to maven central yet. Is there a reason for the delay?
Thanks,
Mark
I've problem to recreate schedule with different cron expression. I can use QuartzSchedulerExtension(system).createSchedule(xxxx)
then I can use QuartzSchedulerExtension(system).schedule(xxxx)
for the first time. However, I've to handle it in different way to recreate it by using QuartzSchedulerExtension(context.system).rescheduleJob(xxx)
.
Should cancelJob
also call removeSchedule
so that we can recreate it again later?
Hi Stephen Hopper,
The scheduler is really very useful, especially for applications which have large amount of actor tasks to schedule in the background.
However, do you notice a post on stackoverflow: http://stackoverflow.com/questions/19727325/akka-quartz-scheduler-never-triggers-my-actor? I also encounter this problem and after checking the source code, still have no clue on how to fix it.
Regards
Wei Zheng
I am using play 2.5.x with Akka-quartz-scheduler - 1.5.0-akka-2.4.x
quartz configuration in application.conf :
defaultTimezone = "India"
schedules {
NowAndThen {
description ="Delete temp files now and then, eg every hour"
expression = "*/1 * * * * ?"
calendars = ["MINIMAL"]
}
TestCalender {
description = "Test calender"
expression = "0 52 13 1/1 * ? *"
calendars = ["TESTTIME"]
}
}
calendars {
MINIMAL {
type = Daily
exclude {
startTime = "19:02:00"
endTime = "19:02:01"
}
}
TESTTIME {
type = Daily
exclude {
startTime = "19:02:00"
endTime = "19:02:01"
}
}
}
In my quartz mapping :
QuartzSchedulerExtension scheduler =(QuartzSchedulerExtension) QuartzSchedulerExtension.get(system);
//Logger.debug("scheduler created");
scheduler.schedule("NowAndThen",cleanupRef,"Clean");
scheduler.schedule("TestCalender", testJob, "Test");
1st actor is invoked but not the second actor.
I tried with single actor with message check but that also not worked for calling the second actor.
Please check this issue.
Quartz have StatefulJob. And this is useful.
Shouldn't it be possible to add custom calendars? I mean, actually calendars are just configurations with no possibility to "customization", like exclude weekends in monthly calendars(it's useful to pick the first business day of a month), because it's all inside QuartzCalendars
and QuartzCalendars
is accessed directly by QuartzSchedulerExtension
, although it's possible to create custom calendars if extends QuartzSchedulerExtension
and access scheduler.addCalendar
internally, i don't think it's a bad practice, or is it?
It seems like when you call, standby, the scheduler is in standby mode, however, the isStarted flag is still true. As such, since the start method only looks at isStarted flag, standby is never able to satisfy the conditions to restart scheduler.
P.S. I love this library. It's saving me so many lines of code.
Hi,
Our product is using the play framework and akka with version 2.2.2. I would like to try this scheduler with our product. We are not planning to upgrade our akka version any time soon. Can you please publish 1.2.0-akka-2.2.x version of the scheduler.
Tag is missing, add it please.
Feature Requested for Actor with Calender quartz exclusion.
Hi Guys, first of all i would like to thank you all for this amazing library. Since one of my app is depends heavily on this scheduler, i would like to know whether there will be an enhancement to support Akka-2.4.0? The reason is i need to implement Akka Persistence
which is based on Akka-2.4.0 and there is no documentation mentioning that this library can work properly with Akka-2.4.0.
Hi All,
I am using this scheduler in my application and found that whenever the schedule method is invoked then the copy of the message is being send down to the the sender class. example :-
schedule("EveryDayAt6AM", , new Date)
In the above example, I am passing new Date as the message to the actor. whenever the scheduler is invoked again then I was expecting the new Date but instead I am always getting the copy of the date object that was first send to the sender when the schedule method was invoked.
Is there a way to always send the new Date object to the sender using the quartz scheduler??
Is it possible to support akka 2.5 with scala 2.11?
I made some tests with the following cron expression
akka {
quartz {
schedules {
Every30Seconds {
description = "A cron job that fires off every 30 seconds"
expression = "*/30 * * * * ?"
}
}
}
}
I played around with different values for the expression but it always stops after 8 repetitions.
I'm importing this version of the library:
"com.enragedginger" %% "akka-quartz-scheduler" % "1.6.0-akka-2.4.x"
Scala version 2.11.6 and play version 2.5.12
If i'm not mistaken, for the moment, the only way to create schedules is to define them in a typesafe config file (application.conf
or other).
In the scenario where a end-user would be able to create scheduled tasks from a UI, how could that be achieved?
Is it possible to do as such, or do we need to add a method to add schedules in QuartzSchedules.scala
?
Thank you for this great library!
I am wondering if there is any way to delete a job which is not running~
After review the code, I found that I can access it by using
QuartzSchedulerExtension. schedules -= (key)
However, the key is not what I have created by
QuartzSchedulerExtension.createSchedule(key, description....)
I have to uppercased the key. (As well as some other operations related to the key, as follows)
if (scheduler.schedules.contains(jobName)){
if (scheduler.runningJobs.contains(jobName))
scheduler.cancelJob(jobName)
else
scheduler.schedules -= (jobName) //delete
}
Hope that you can giving some explanation.
Is there a way to get the scheduler instance if I have the scheduler name?
This project is looking for a new maintainer! Please notify us in this issue if you would like to take over this project. It will be deleted in a few months unless we find a new owner.
Hi,
I have a scheduleconfigured that's named "EveryMinuteDuringWeekdays". I want two distinct actors to receive a Tick-message on that named schedule. If I schedule the ticket message for only one actor, it works fine. If I want to schedule it for the other actor as well, I get an exception.
Exception:
org.quartz.ObjectAlreadyExistsException: Unable to store Job : 'DEFAULT.EveryMinuteDuringWeekdays_Job', because one already exists with this identification.
Code:
val scheduler = QuartzSchedulerExtension(system = context.system) scheduler.schedule("EveryMinuteDuringWeekdays", self, Tick) scheduler.schedule("EveryMinuteDuringWeekdays", receiver, Tick)
Looking at the source of akka-quartz-scheduler I cannot seem to find the correct way on how I'd make sure that more than one actor can be on a schedule. Could you point me to the right direction?
I have the following actor in Play for Scala that injects a class with Guice:
class MainEtl extends Actor {
@Inject val me2 : MainEtl2 = null
def receive = {
case option: String => {
val x = me2.run(option)
// ... more code
}
}
}
When I try to schedule it I get an error as me2 is null:
[error] a.a.OneForOneStrategy - null
java.lang.NullPointerException: null
at tasks.etl.MainEtl$$anonfun$receive$1.applyOrElse(MainEtl.scala:17)
at akka.actor.Actor$class.aroundReceive(Actor.scala:484)
at tasks.etl.MainEtl.aroundReceive(MainEtl.scala:8)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
at akka.actor.ActorCell.invoke(ActorCell.scala:495)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
at akka.dispatch.Mailbox.run(Mailbox.scala:224)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
This is how I invoke it:
val scheduler = QuartzSchedulerExtension(system)
val receiver = system.actorOf(Props[MainEtl])
val d = scheduler.schedule("mycron", receiver, "abc", None)
How to get a reference to an injected object when the Actor is invoked from Akka-Quartz-Scheduler? I also tried injecting with @Inject as class parameters but that doesn't work either.
This is class MainEtl2 code:
class MainEtl2 @Inject() (ic: injectedClass) {
def run (option: String) = {
ic.method1()
// ... some code
}
}
Hi, I am currently using this tools in my own project. Is the maintainer still here? If not, can I help with maintain the project? I saw a PR has not yet been merge for 7 months and I myself have some code to push...
It seems ActorRef is deprecated. Could this project change to ActorSelection?
I have an akka project written in Java. So, is it possible to use akka-quartz-scheduler in a java project? Or should I build and create a package to use in my project?
Is it possible to stop a scheduler after x number of times? Or specify an end time?
It would be nice to be able to reference a schedule from multiple jobs so one does not have to replicate the schedule for jobs with the same scheduling.
It's still using 2.2.3, which is causing conflicts from its transitive dependencies.
Any possibility of a build for Scala 2.11.12 and Akka 2.5.12
reason: It looks like Spark is not upgrading to Scala 2.12.x at all.
We have an existing project that is using Scala 2.10, and I would like to use Akka 2.3 and also akka-quartz-scheduler. I see that akka-quartz-scheduler for Akka 2.3 is only compiled for Scala 2.11. Since Akka 2.3 also supports Scala 2.10, can you please publish a version for Scala 2.10? Thanks!
After suspending the scheduler, it can no longer be resumed.
val scheduler = PatchedQuartzSchedulerExtension(system)
scheduler.standby()
scheduler.start() // this line logs a warning saying it's already started
This is because the start
method only checks the value of the isStarted
field, but not the isInStandbyMode
field.
Proposed patch:
def start(): Boolean =
if(isStarted && !isInStandbyMode) {
log.warning("Cannot start scheduler, already started.")
false
} else {
scheduler.start()
true
}
Hi, I just wanted to use your lib with playframework-java app.
I created sample project - https://github.com/sleski/play-akka-quartz-example
I created two actors which should be triggered by cron scheduler every 10seconds.
But this does not work. App starts, from log looks like it should be triggered:
[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@746cb637'
[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@34d78b1c'
I did not find any informations how to configure it in play java app, may some configuration is missing?!
I will be grateful for any tip/help.
Hi there,
I'm seeing an issue where a job is triggered on initialization.
val scheduler = QuartzSchedulerExtension(system)
scheduler.schedule("EverySunday", treatmentRunner, Run)
scheduler.schedule("EveryNight",
lotteryNotificationRunner,
Run,
startDate = Some(new DateTime("2017-05-26T00:00").toDate))
scheduler.start()
This is what the scheduling looks like:
quartz {
schedules {
EverySunday {
description = "a job that fires every Sunday"
expression = "0 0 17 ? * TUE" // 5 PM on sunday
timezone = "Africa/Nairobi"
}
EveryNight {
description = "Every night at 7pm"
expression = "0 0 19 * * ?"
timezone = "Africa/Nairobi"
}
}
There's no other place that could be sending this message to this actor. I'm a little confused as to why the "LotteryNotificationRunner" is executing on startup.
I'm using quartz scheduling in a scala project. Scheduling works fine unless a calendar is specified for a schedule. In that case, the task is never triggered by the scheduler. Example:
akka { quartz { defaultTimezone = "America/New_York" schedules { WeeklyEmailSchedule { description = "7:00 am every Friday" expression = "0 16 11 ? * FRI" } DailyEmailSchedule { description = "7:00 am every day" expression = "0 0 7 ? * *" calendar = "DailyCalendar" } } calendars { DailyCalendar { type = Weekly description = "Daily excluding friday" excludeDays = [6] excludeWeekends = false } } } }
If I comment out the line: calendar = "DailyCalendar"
then everything works as expected. What am I doing wrong? Is my calendars prop invalid in any way?
Library version:
"com.enragedginger" % "akka-quartz-scheduler_2.11" % "1.4.0-akka-2.3.x"
Thanks so much!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.