Prevent Job execution if job was scheduled to be executed in the past? - hangfire

I'm looking for a way to prevent Hangfire from executing a job which has been scheduled to be executed in the past. For instance, if Product import is scheduled to be run at 4am, but server goes down and only comes back up at 7am, Hangfire it execute the 4am job immediately. I want to prevent this, any ideas?
What complicates matters, is that I still want to be able to execute the job manually when necessary, so I cannot hard-code a check to make sure job doesn't execute outside of 4am window.
Any ideas would be welcome.
More here https://github.com/HangfireIO/Hangfire/issues/620

Related

Is it possible to schedule a Retry for a SQL job instead of its Step components whenever one of the Steps fail?

I am using SQL Server 2014 and I have a SQL job (an SSIS package which contains 11 steps) which has been scheduled to run on a daily basis at a specific time.
I know one can schedule each step to attempt a retry whenever that step fails. However, is there a way to configure a retry for the whole SQL job whenever the job fails at any step during the process? That is, if say, the job fails at Step 8, the whole job is run again from Step 1.
The tidiest solution I can think of would be creating an error handling Step in your Job which will be executed when any other step fails (change the On Failure action of all other steps to jump to this one) and managing the job's schedule to trigger again on the following minute, after the job ends. This way you will see the execution history of the job at the agent.
You will have to keep in mind recurrent failures, I doubt you want the job to be repeating itself indefinitely.
To configure the job to trigger, you can add a Schedule that fires every minute and enable/disable it when necessary. The job won't fire if it's already running.

SSIS Agent job keeps running as "inprogress"

I have a SSIS package that monitors a folder. This package will run continuously until it's terminated.
I want to schedule this using a SQL Agent job.This SQL Agent job will utilize two steps. It is kind of heart beat job to to make sure the SSIS package runs.
Step - 1 it checks whether the SSIS package is running. if running quit else step 2.
Step - 2 Execute the SSIS job. if OK then report success and quit else report failure and quit.
uses a daily schedule Mon-Fri every 4 hrs.
When I execute the SQL Job, it starts the SSIS package but the job keeps running and the job monitor and history shows it as "inprogress"
I had to close the job to come out of the dialog but in background the SSIS job is still running as expected.
Is this normal behavior ? Do I need to approach this in a different way ?
Appreciate any pointers or help on this.
Once the job has begun, the Start Jobs dialog box has no impact whatsoever on the running of the job itself - it exists solely to provide a monitoring window for you. Closing it will have no effect on the running job.
From other phrases in your question, I gather that you do not expect the job to ever 'finish' - therefore I would expect it to always show as In Progress unless it errors out or is stopped.
"This package will run continuously until it's terminated."
"The job keeps running and the job monitor and history shows it as in progress"

Hangfire queues recurring jobs

I use hangfire to run recurring jobs.
My job get current data from the database, perform an action and leave a trace on records processed. If a job didn't run this minute - I have no need to run it twice the next minute.
Somehow I got my recurring jobs (1 minute cycle) queued by their thousands and never executed. When I restarted my IIS it tried to execute them all at once and clog the DB.
Besides than fixing the problem of no execution, is there a way to stop them from queuing up?
If you want to disable retry of failed job simply decorate your method with an AutomaticRetryAttribute and set Attempts to 0
See https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.Core/AutomaticRetryAttribute.cs for more details

How to detect APScheduler's running jobs?

I have some recurring jobs run frequently or last for a while.
It seems that Scheduler().get_jobs() will only return the list of scheduled jobs that are not currently running, so I cannot determine if a job with certain id do not exists or is actually running.
How may I test if a job is running or not in this situation?
(I set up those jobs not the usual way, (because I need them to run in a random interval, not fixed interval), they are jobs that execute only once, but will add a job with the same id by the end of their execution, and they will stop doing so when reaching a certain threshold.)
APScheduler does not filter the list of jobs for get_jobs() in any way. If you need random scheduling, why not implement that in a custom trigger instead of constantly readding the job?

SQL Server Agent Job is not running

I have a job that is supposed to run every 11 AM and 8 PM. About two weeks ago, it started to not respect the schedule. The "fix" that I found was to start the job manually and then the job would restart respecting the schedule for a while but eventually the issue reappears.
The big problem is that there are no error message what so ever. If the job fails, I am supposed to get a notification Email which I do not. In the sql server agent logs and the Job history, there are no errors. In the job history, I can see clearly that the job skipped the schedule since there are no entries. It looks like it did not even start as if the running time had not arrived.
The schedule is set to run everyday and there are no limits on how long it is supposed to run. The sql Agent is set to restart automatically if it stops unexpectedly.
Did anyone get this problem before?
Check the user which is used to run the job. Maybe the user password is expired or the user itself is no longer active.