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
Related
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.
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
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
I have a quartz.net client/server setup to fire some text messages on a schedule using another Third Party library.
Quartz.Server.exe is running as a windows service on my staging and development environments, pointing to jobs on SQL and my website uses Quartz.Simpl.ZeroSizeThreadPool and just schedules the jobs. Everything was working fine until it wasn't.
Apparently something had caused the exe to stop running and even though it was running as a windows service with recovery options set to send me an email when it went down, I did not get the email.
So when I restarted the server 15 days worth of old text messages went out with misleading phrases like "Appointment tomorrow # 9:00 AM" for appointments for 5 days ago.
So now I have updated my IJob code so that the job is discarded if the fire-time is after the appointment time. Since I was using DateTime instead of plain strings I changed "quartz.jobStore.useProperties = false". When I was ready to deploy I realized that this change along with some other changes could break the scheduler so that it wouldn't fire historical triggers from before the changes.
I spiraled down a 12+ hour black hole trying to wrestle with the settings to get my new jobs to fire alongside my old jobs locally and on my staging environment. Tried a million things, including every combination of Quartz running as a service or console pointing to SQL local or on staging. Said potty-words. Then said some prayers.
Started over. Tested to see if the working code on the live server would fire both new and old jobs without testing. It wouldn't. I Changed "quartz.jobStore.useProperties = false" in quartz.config. It worked! So I did a new deployment Monday evening with the changes and everything seemed to be working fine. I did a "Keeping my job dance", and revisited my error logging/recovery setup and created a nightly job in SQL to count number of triggers yesterday, today, and tomorrow each morning.
Here it is Wednesday morning and I check the SQL job I set up to find 150+ triggers from Yesterday have not been handled (everything past 9:00 AM EST). So I go to my live server and the Quartz service is still running. I stop the process and go to my folder where it lives and Right_Click>Run as Admin. Here is the error I get in my log.txt file. And of course now the Windows service fails to start.
I need major help fast! I need a montage, and at the end of the Montage I need to be a quartz.net ninja. Marko Lahma (or anyone) will you "hold my hand" and tell me I am going to be able to keep my job? I need my setup to be bulletproof (be more robust/fail more noticeably).
EDIT - 201404241938Z
Here is my code to check for the new values that broke the old jobs
// I think this next line is causing an error
DateTimeOffset oDateReminder = data.GetDateTimeOffset("reminderTime");
if (oDateReminder.DateTime > DateTime.MinValue)
{
// Do stuff with other "new job" datamap keys
…
// Changing it to…
if (data["reminderTime"] != null)
{
// Do stuff with other "new job" datamap keys
…
EDIT - 201404242205Z
This seems to have worked. I'll wait and award some bounty
As you probably know, the data is now corrupted in the DB containing both JobDataMaps (binary) and NameValueCollections (binary).
Would you like to give a whirl to the latest head of repository master? I've ninjacommitted support for recovering from this mixed data situation. Just take the latest and build with custom snk file and drop the DLL for run.
This is version 2.2.x so take note if you are using something like 2.1 or 2.0.
The issue is tracked here https://github.com/quartznet/quartznet/issues/172
What comes to your original issue one easy fix would to ignore misfires, if SMS notification doesn't fire within expected time then it probably should be ignored and not fired immediately when possible. Logging information might help you get info about what caused the original downtime (windows updates, SQL server not started yet etc).
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.