How to postpone a delayed job in Hangfire using SQL script - sql-server

We have been using Hangfire v.7 with SQL Server for a long time and have a lot of delayed jobs. I want to find those scheduled to run in a specific period (e.g. from 2030-01-01T01:00:00 to 2030-01-01T03:00:00) and postpone them for N hours. I assume there are some columns in the Hangfire database that specify the execution time of each job. Is it valid? How can I change the execution time of delayed jobs via a SQL script?

I've read the Hangfire source code and followed the process starting from BackgroundJob.Schedule, which is the API method for creating a new delayed job, until the changes it commits to the DB. This is the DB schema:
Every delayed job has a record in the [Job] table and its execution data is saved in the [State] table. An unexecuted scheduled job has a state record like this:
The [Data] column has scheduling details in JSON format. The value of EnqueueAt is when the job is supposed to start execution in the UNIX time stamp. For SQL Server v.16 or higher a script like this can be useful:
UPDATE [State]
SET JSON_MODIFY([Data], '$.EnqueueAt', '0000000000000'/*put your time stamp here*/)
WHERE condition

Related

When Dba_Scheduler_Jobs.Start_Date is not specified, where does Oracle store Job Enabling time

I've a question on DBMS_Scheduler functionality:
When I create a scheduler job via DBMS_SCHEDULER.CREATE_JOB proc and I don't specify Start_Date value, then job is scheduled for execution as soon as it is enabled which is correct. I want to know where does Oracle store the Job enabling time because same enabling time can be seen in dba_scheduler_job_run_details.Req_Start_Date when job finishes.
Basically I want to see enabling time for a job which is in SCHEDULED state and Start_date value for that job is NULL.
Thanks for sharing knowledge!
The job enabling time appears to be stored in SYS.SCHEDULER$_JOB.LAST_ENABLED_TIME.
But since that is an undocumented table, I can't say with great confidence that my answer is always correct.

How to change the retention period for CDC or put a condition on it (SQL Server 2012)

I'm in a SQL Server 2012 environment, and I have CDC enabled on a table. To sum, the table is used to populate a data warehouse (basically, the content of the table is duplicated elsewhere).
However, I just noticed that we are losing a lot of data because CDC was enabled with the default setting of 3 days. I know how to write a query that enables a CDC with a NEW/DIFFERENT retention period. But that's not the task, the task is that I must be able to change the current CDC setting. So, is there a way to ALTER the retention period?
Also, additionally, is there a way to prevent CDC from deleting expired records all in all? meaning, is there a way to implement a flag that prevents the CDC to delete any records UNLESS that record has already been transferred/moved.
Thank you very much!
sys.sp_cdc_change_job is what you're looking for to change the retention.
As to your second question, there is no way for CDC to know what rows you've processed and not. So, you have to set your retention period such that you have enough time to process the records that have accumulated since the ETL job last ran. The typical workflow that uses CDC runs on a regular periodic basis (e.g. daily, weekly). So I smell something odd when you say that you're losing data (unless the current retention period is set lower than the time between ETL runs).
Specifically, the following command can be used (pursuant to the answer above):
EXECUTE sys.sp_cdc_change_job
N'cleanup',
#retention = RetentionTimeInMin --this is a number in minutes

Time of jobs when they scheduled in task scheduler

I have many talend jobs, I am executing all those jobs in windows scheduler (task scheduler). I need to store the time of those jobs when they scheduled. how I can get the time of that? Please assist me on this.
Windows Scheduler already stores a list of executed scheduled tasks where you can see the execution of tasks in either the last hour, day, week or 30 days.
If you're looking for something more programmatic and accessible from outside of Windows Scheduler then you could output something in the Talend job itself.
For example you could start your job with a quick entry to a log file or database table with the date-time of execution and the job name (retrievable from Talend's time handling functions and also system variables - try hitting ctrl+space to see a list of variables available to you) that is started and then finish the job with another log in the log file or database table with an entry for whether it succeeded or failed and the time that the job finished along with the job name.

SQL Server 2005: Schedule Start/Stop of TSQL Script

Currently running SQL 2005 on Server 2005. I have a TSQL script which updates 1000 rows at a time. It loops through a counter until there are no rows to update.
In my situation, I have a lot of rows to update and I need to run this "after hours". So I would like to see if there is a way that I can schedule a way to automatically start and stop a task based upon a set time. I am thinking that I could place this task in a SP and start it with SQL Agent. However, I can not think of how to stop the task automatically. I'm open to SSIS too.
You can use a SQL Job, and make this call a stored procedure or some sql. The job can be set on a timer, for specific days etc.
See Creating a Job for help
You can schedule following T-SQL to stop jab as well.
USE msdb ;
GO
EXEC dbo.sp_stop_job N'Your job name' ;
http://technet.microsoft.com/en-us/library/ms182793.aspx

Execute long running jobs in SQL Server

I am working with SQL Server 2008. Using the Agent, I have created a job and scheduled it to execute every minute.
The job executes a stored procedure that moves data from table XXX, to a temp table, and then eventually into table YYY.
The execution of the job may take more than one minute - since the data is rather large.
Will a second instance of the job be started even though the first instance is still running?
If so, should I mark records in temp table (status = 1) to indicate that those records are being processed by a previous instance of the job?
Is there a way for me to check that an instance of the job is currently running, so that I don't initiate a second instance of the job?
Is there another solution for this that I am unaware of? (throughput is important)
Only one instance of a particular job can run at any one time.
So there is no need to take any particular precautions against another execution of the same job beginning before the first one has stopped.
check this post
How to Prevent Sql Server Jobs to Run simultaneously
How to Prevent Sql Server Jobs to Run simultaneously
As Well HERE
Running Jobs
http://technet.microsoft.com/en-us/library/aa213815(v=sql.80).aspx
If a job has started according to its schedule, you cannot start another instance of that job on the same server until the scheduled job has completed. In multiserver environments, every target server can run one instance of the same job simultaneously.

Resources