How to solve the sleeping problem in Quartz.NET (C #)? - c#

I am having a problem with Quartz.NET to create a job on a system. The Quartz is sleeping 23:50 and waking up 7:26 AM.
I have a job scheduled for 00:00
System Information: 1 - .NET Application 2 - IIS Server
Application log:
enter image description here

I personally just use quartz job calculator the set job execute time when server is up
https://www.freeformatter.com/cron-expression-generator-quartz.html
and have the ability to manually start them later if needed.
You can also create a job that automates this. For example it runs every 10m that checks if some other job has to be run. It does so by checking when it was last ran, and if it is ran it will set a sync lock - a simple local time, so you can check if some amount of time ex: 1 day has passed.

Related

How do I make Quartz Scheduler to run every hour not to run if the previous hour's job is not yet completed?

I did setup a Cron Job that runs every hour in C# as a service; it sweeps files from a folder and dumps them onto ftp, however during busy hours one hour is not enough, how do we make sure that the previous hours job is completed first before starting this hours job.
There's an attribute called [DisallowConcurrentExecution] which you can use. Refer to the documentation pertaining to the exact version of Quartz Scheduler.NET that you are using.
You can find more info about it at https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/more-about-jobs.html

Hangfire keeps running recurring jobs late

So I have several recurring jobs that are supposed to run on a certain hour:
RecurringJob.AddOrUpdate(() => Runner.SendTestEmail(), Cron.Daily, TimeZoneInfo.Local);
RecurringJob.AddOrUpdate(() => Runner.CleanProjectFiles(), "0 0 * * *", TimeZoneInfo.Local);
RecurringJob.AddOrUpdate(() => Runner.IPAudit(), Cron.Daily, TimeZoneInfo.Local);
These are all supposed to run at midnight, however they are running at all times of the day.
The last time all of my midnight jobs ran was at 5:13 AM.
I checked the time and timezone of the box hosting the site, I set the QueuePollInterval to 15 seconds but things are still running several hours late.
The SQL box is different from the box hosting the site, however I made sure to check the time there as well to make sure that everything was the same.
Does anyone have any suggestions as to how I could fix this issue?
Is there something I have to configure in IIS?
Thank you UtopiaLtd, your answer worked perfectly.
Is your app pool set to recycle with no traffic? With Hangfire, if a tree is scheduled to fall in the forest, it will wait to make a sound until there's someone to hear it, so to speak. The app pool needs to be alive for Hangfire to run

Best way to run process on certain hours

Hi I have a Windows Service in C#. Inside my windows service I need to run a process on determined hours hh:mm:ss.
For example I need to run the process at:
09:50 hrs
11.45 hrs
15:15 hrs
22:05 hrs
(These hours can change, so Im thinking in storing those in a XML file)
Right now I used to have a timer with interval of 6 hours, so every 6 hours the process was executed. Now the requirement is other. I need to run on a specific schedule.
Also I was requested to add an option that the windows service can run the process on every X hours and Y minutes.
Any clue how can I code that?
Thanks.
Another good way could be using Quartz
Quartz.NET
Quartz.NET is a full-featured, open source job scheduling system that
can be used from smallest apps to large scale enterprise systems.
Job Scheduling in Quartz
Jobs are scheduled to run when a given Trigger occurs.
Triggers can be created with nearly any combination of the following
directives:
at a certain time of day (to the millisecond)
on certain days of the week
on certain days of the month
on certain days of the year
not on certain days listed within a registered Calendar (such as business holidays)
repeated a specific number of times
repeated until a specific time/date
repeated indefinitely
repeated with a delay interval
Why reinvent the wheel? Just use Windows Task Scheduler to run your process.
If you want to setup the task scheduler from your code, you can use the Managed Task Scheduler Wrapper

Quartz Fire Time is off by an hour

I recently upgraded from 1.x to the latest version 2.1.2. I ran the db scripts and made the necessary code changes and we're just testing it now. Everything seems to work as expected with one odd exception. We have a little UI that we query the qrtz_trigger table for so we can see all the schedules when things will run.
When I schedule a Job with a daily CRON trigger it will run at the correct time the first run, but the subsequent time it will be off by one hour. So for example say I schedule a daily job to run at 2:30 PM every day, my cron expression looks like:
0 30 14 ? * MON-SUN
And the CRON expression appears as such in the db as well. When I look in the qrtz_triggers table I see the following (converted from ticks):
NEXT_FIRE_TIME: 2013-08-15 14:30:00.000
PREV_FIRE_TIME: NULL
So far so good. But then the trigger fires, runs the job and the qrtz_triggers table is updated to:
NEXT_FIRE_TIME: 2013-08-16 13:30:00.000
PREV_FIRE_TIME: 2013-08-15 14:30:00.000
We keep all our servers running on UTC to avoid confusion.
Is this a bug? What might be going on here? We don't see this behavior in 1.x

How to run background service on web application - DotNetNuke

I made dnn scheduler and set to run it on every 1 min. It works when I do something on site. But I need to run some actions when I am not on the site. For example insert record to database with currenct time. Is this possible?
In Host Settings, use Scheduler Mode = Timer Method
This will make the scheduler run in a separate thread that is not triggered by page requests.
If the scheduler runs in the timer method, it won't have access to the current HttpContext.
You will also have to make sure that DNN is kept alive, and IIS doesn't shut down the application due to inactivity. Setting the application pool idle timeout appropriately, and pinging the /Keepalive.aspx should take care of this. Nevertheless, using the DNN scheduler for critical tasks is not a good idea.
See Also:
Creating DotNetNuke Scheduled Jobs
DotNetNuke Scheduler
Explained
If you just want database related things, such as inserting a record, you can use database jobs. You didn't mention what dbms you use but almost every database have almost same functionality under different names.
Doing the equivalent of a Cron job is still a pain in the butt on Windows.
The DNN Scheduler will work if you aren't super concerned about when it runs. What you may need to do is have more logic on your end... if it only runs every 10 minutes, or every hour or whatever you may have to look at your database tables, determine last time it ran and then do whatever it needs to do to 'catch up.' In your case add 60 minutes of info versus every minute.
I'm struggling to think of an example of why I would just write to a table every minute or on some interval. If I needed it for a join table or something convenient to report off of you should generate them in larger chunks.
The other option is to write a small .NET windows service which isn't that hard and have it run every minute. That would be more reliable.

Categories