How to run job every 15 mins using quartz in mule - mule

How to configure corn expression to run the job every 15 mins.
Configured below one in the code but it is not working
fp.cron.expr=0 15 0 ? * *
Can you please help on this

You can use the Poll Scheduler in this case and give the Cron scheduler expression as
0 0/15 * 1/1 * ? *
For reference -->
https://docs.mulesoft.com/mule-user-guide/v/3.6/poll-schedulers

You expression is wrong, a job which run every 15 mn should look like this : 0 0/15 * * * ? *

Quartz connector is deprecated. When scheduling tasks, it’s recommended that you instead use the Poll Scope. It has option for Fixed Frequency Scheduler and Cron schedular. With Fixed frequency you can choose time units in MILLISECONDS, SECONDS, MINUTES, HOURS and DAYS.

You can try 0 0/15 * 1/1 * ? *. You can visit Cron Maker site to generate your cron expression.

Right expression is "0 0/15 * * * ?"
Visit https://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/crontriggers.html for further reference.
If the above expression is not working then you can also use a trigger like as below :
scheduler.Start();
IJobDetail job = JobBuilder.Create<JobName>().Build();
ITrigger trigger = TriggerBuilder.Create().StartNow().WithSimpleSchedule(x => x.WithIntervalInSeconds(15).RepeatForever()).Build();
scheduler.ScheduleJob(job, trigger);

Related

Setting Cloudwatch Event Cron Job

I'm a little bit confused on the cron job documentation for cloudwatch events. My goal is to create a cron job that run every day at 9am, 5pm, and 11pm EST. Does this look correct or did I do it wrong? It seems like cloudwatch uses UTC military time so I tried to convert it to EST.
I thought I was right, but I got the following error when trying to deploy cloudformation template via sam deploy
Parameter ScheduleExpression is not valid. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException
What is wrong with my cron job? I appreciate any help!
(SUN-SAT, 4,0,6)
UPDATED:
this below gets same error Parameter ScheduleExpression is not valid
Events:
CloudWatchEvent:
Type: Schedule
Properties:
Schedule: cron(0 0 9,17,23 ? * * *)
MemorySize: 128
Timeout: 100
You have to specify a value for all six required cron fields
This should satisfy all your requirements:
0 4,14,22 ? * * *
Generated using:
https://www.freeformatter.com/cron-expression-generator-quartz.html
There are a lot of other cron generators you can find online.

Run Job every 4 days but first run should happen now

I am trying to setup APScheduler to run every 4 days, but I need the job to start running now. I tried using interval trigger but I discovered it waits the specified period before running. Also I tried using cron the following way:
sched = BlockingScheduler()
sched.add_executor('processpool')
#sched.scheduled_job('cron', day='*/4')
def test():
print('running')
One final idea I got was using a start_date in the past:
#sched.scheduled_job('interval', seconds=10, start_date=datetime.datetime.now() - datetime.timedelta(hours=4))
but that still waits 10 seconds before running.
Try this instead:
#sched.scheduled_job('interval', days=4, next_run_time=datetime.datetime.now())
Similar to the above answer, only difference being it uses add_job method.
scheduler = BlockingScheduler()
scheduler.add_job(dump_data, trigger='interval', days=21,next_run_time=datetime.datetime.now())

apscheduler at 90 second intervals?

Is it possible to set an apscheduler cron job to run at 90 second intervals? (I have 40 machines that I'd like to schedule evenly over an hour without hard coding time info into the script). I've tried various kinds of this:
job = sched.add_cron_job(_test, minute='*/1', second='30')
job = sched.add_cron_job(_test, minute='*', second='90')
Try this instead:
job = sched.add_interval_job(_test, seconds=90)
Based on your question you want to start a cron job at a particular time and run it indefinitely with 90 seconds interval. You can achieve this by combining triggers
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.combining import AndTrigger
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.triggers.cron import CronTrigger
def _test():
print("code comes here")
scheduler = BackgroundScheduler()
# Runs on 2019-12-30 at 5:30 (am) & repeats every 90 seconds interval
trigger = AndTrigger([IntervalTrigger(seconds=90),
CronTrigger(start_date='2019-12-30', hour=5, minute=30)])
scheduler.add_job(_test, trigger)
scheduler.start()
Interval code example:
sched = BlockingScheduler()
sched.add_job(ClassTest, 'interval', seconds=90)
sched.start()

How to define every five minutes to run jobs

How to define every five minutes to run jobs
in the play.jobs.every class ,it define an example every("1h") to run job every hour,bu i want to run every 5 minutes,how to define this.
i try the every("5m") or every("0.1h") ,play reports internal error.
Short answer:
You can use either of the following
#Every("5mn")
#Every("5min")
Long answer:
The #Every annotation uses the play.libs.Time class, and specifically the parseDuration method to determine how often the job is scheduled.
If you look at the source code, the Javadoc states...
/**
* Parse a duration
* #param duration 3h, 2mn, 7s
* #return The number of seconds
*/
This would suggest that you should specify your code as #Every("5mn")
If you look deeper into the code, it determines that the time is in minutes by using the following regular expression.
"^([0-9]+)mi?n$"
So, this states that either of the following are valid
#Every("5mn")
#Every("5min")
Try using "5min" in your annotation instead:
#Every("5min")

Can you alter the polling time interval (5 seconds) for delayed_job worker?

Delayed job is great, but I would like to change its timer interval to be more frequent (every 2 second) to meet my special need.
Is there a config or hard-coding anywhere to change it?
With DJ 3.0 you can add this to the config/initializers/delayed_job_config.rb file:
Delayed::Worker.sleep_delay = 2
Try setting
Delayed::Worker.const_set("SLEEP", 2)
in your config/initializers/delayed_job_config.rb file.
Sure, just go to RAILS_ROOT/vendor/plugins/delayed_job/lib/delayed/worker.rb, look for the line
self.sleep_delay = 5
and change it to
self.sleep_delay = 2
or whatever you'd like
On an earlier version of DJ I set this to as little as 0.1 so that the jobs in the queue get picked up for processing almost instantly and it works just fine.