Schedule single package from within SSIS package - tsql

I have a SQL job agent that has two job steps: PackageA and PackageB.
PackageB follows PackageA but PackageB should never run between 06:00 and 18:00.
Unfortunately, PackageA sometimes takes a long time causing PackageB to run between 6:00 and 18:00.
In PackageB I have a constraint+expression that checks whether the time is between 06:00 and 18:00. If so, PackageB exits nicely and sends an email to an operative reminding him/her to reschedule PackageB.
However, things would be very much better if I could have the package reschedule itself.
Logic in PackageB:
ExpressionTask --> fills variable #Hour with datepart("Hh",GETDATE())
If the found value is <6 or >18 the 'normal' procedure is executed or it starts an 'send email' and exits.
What I would like is to add a command after sending the email that would schedule PackageB to run once that same evening at 19:00. Ideally the procedure would check whether there is a job for just running packageB and schedule that to run once that evening at 19:00 and if there is no existing
job for running PackageB it should be created.
My feeling says this should be doable using TSQL. Any suggestions or are there better ways to do it besides using TSQL?
Thanx for thinking with me!

You can implement a T-SQL job step between PackageA and PackageB or a Execute SQL Task in SSIS that checks the time and uses the WAITFOR statement to wait till 19:00.
IF DATEPART(HOUR, SYSDATETIME()) >= 6 OR DATEPART(HOUR, SYSDATETIME()) < 18
BEGIN
WAITFOR TIME '19:00';
END;

Related

Irregular Trigger BizTalk Scheduled Task Adapter

I have several receive locations of type schedule in a BizTalk 2016 server. All except one work fine. This one has been getting triggered as defined in the schedule daily at 04:00 am, however it suddenly began to start at 05:00 pm and one day it didnĀ“t run.
There is no Error Log in the Application Logs or the SQL Logs. The Receive Location is enabled. The Server Time is correct.
Does anyone has a hint, what this behavior might be caused by?
BTS 2016
Scheduled Task Adapter 6.0.0.6
The current version is 7.0.2. and that includes some fixes
e.g.
In certain cases task won't trigger in set time with Timespan with Biztalk 2016
Timly Schedule Start Time (and Date) doest not work correct
So I would suggest downloading and installing 7.0.2.
I experienced a similar behavior when the Host Instance is shared and sometimes overloaded. Try to dedicate a HI for scheduling only. And as suggested by #Dijkgraaf, you can use the last version of this Adapter

Task Scheduler executes too early

I currently have two custom tasks in my Task Scheduler which have nearly the same trigger configured except one is executing 15 minutes after the other one
As you can see in the image above, one of the Tasks, was executed 1 DAY earlier than it should have.
In the history I can see that it says that its executed due to scheduler, but that's actually not true because there is only one trigger configured like this:
as you see below, it executes also on the first as it is in the scheduler, last month i also had the problem that it was executed one day earlier, i reconfigured everything and now i have the same problem again, probably its going to execute tomorrow also.
these are my other settings:
the tasks are running on a 2016 Server 1607
Does anybody know about any issues with monthly schedules?
i saw that in the 2019 Server there is a problem that on monthly tasks the tasks probably wont execute at all.
so this seems to be an issue inside Windows 2016 Build 1607.
I changed the time so it does not execute on 02:00 to 02:05AM and the task executed correctly.
I don't know why this is an issue or if only 02:00 is bugged but we opend an issue at microsoft for this.

Moodle: Scheduled tasks set for one minute sets itself to ASAP, but never reruns

I have been monitoring the Complete learning plans which are due task, which is set to run every minute. I have set the cron.php script with a password to force the cron job to run. When I reload the page I notice that the cron job runs, sets the next run date time, but doesn't run again and changes to ASAP.
I am using Moodle 3.6.3 on Windows IIS.
Create a task in task scheduler to execute the script after every minute (or any time you want). Use "Start a program" action. Replace "C:\Program Files\PHP\v7.2\php-win.exe" with your php version and also change the moodle path to yours.

preferred pattern for conditional execution of a Talend job

I have a Talend job (call it A) that I want to run when an Oracle stored procedure (not executed by Talend) has completed. I have an Oracle control table that I can check to see if the Oracle SP has finished.
I am imagining having my Talend job A run on a schedule - perhaps every 15 minutes - and the first thing that it would do is determine if A has already executed today. If it has already run today it would stop execution immediately. If it has not yet run today, it will check to see if the Oracle SP has completed, and if not, it will stop execution immediately. This should result in Talend job A only executing once a day, and only after the Oracle SP has completed.
Is there a more elegant way to accomplish this?
Thanks.
As you've stated in the comments, Oracle SP has a CronJob.
You should make a Talend Job (A) which will be executed shortly after the Oracle SP start. This would have an Iterate + tOracleInput-tJavaRow + tRunJob + tJava
Iterate (i<=80 && somevalue==1 --> tOracleInput - row1 - tJava --
--IF--> row1.field.equals("true") --> tJava i = 101; --> tRunJob(JobB)
--IF--> !row1.field.equals("true") --> tJava Thread.Sleep(15*60*1000);
This way when you execute the JobB you'll exit from the loop. Also your Talend Job will run once a day, and does the calculation once a day. I know it seems to be a little dirty but it will work.
Having i set to 80 you'll end up with 81 trys thats 20hour 15min for the worst case not counting the query runtime.
Thread.Sleep accepts miliseconds thats why you need to multiply by 1000 to get the seconds and 60 to get the minutes
You can also think below options
1) export/build your talend job (A) as shell/batch file and execute it via same unix crontab job which executes your SP. You have to set dependency may be based on exit code of SP job.
OR
2) you can run your SP from talend job either using tOracleSP or even you can run your unix shell if any existing using tSystem and onSubJobOk run your talend job (A).

Run SSIS Package from T-SQL

I noticed you can use the following stored procedures (in order) to schedule a SSIS package:
msdb.dbo.sp_add_category #class=N'JOB', #type=N'LOCAL', #name=N'[Uncategorized (Local)]'
msdb.dbo.sp_add_job ...
msdb.dbo.sp_add_jobstep ...
msdb.dbo.sp_update_job ...
msdb.dbo.sp_add_jobschedule ...
msdb.dbo.sp_add_jobserver ...
(You can see an example by right clicking a scheduled job and selecting "Script Job as-> Create To".)
AND you can use sp_start_job to execute the job immediately, effectively running SSIS packages on demand.
Question: does anyone know of any msdb.dbo.[...] stored procedures that simply allow you to run SSIS packages on the fly without using sp_cmdshell directly, or some easier approach?
Well, you don't strictly need the sp_add_category, sp_update_job or sp_add_jobschedule calls. We do an on-demand package execution in our app using SQL Agent with the following call sequence:
- sp_add_job
- sp_add_jobstep
- sp_add_jobserver
- sp_start_job
Getting the job status is a little tricky if you can't access the msdb..sysjobXXX tables, but our jobs start & run just fine.
EDIT:: Other than xp_cmdshell, I'm not aware of another way to launch the the SSIS handlers from withinSQL Server. Anyone with permissions on the server can start the dtexec or dtutil executables; then you can use batch files, job scheduler etc.
Not really... you could try sp_OACreate but it's more complicated and may not do it.
Do you need to run them from SQL? They can be run from command line, .net app etc
In SQL Server 2012+ it is possible to use the following functions (found in the SSISDB database, not the msdb database) to create SSIS execution jobs, prime their parameters, and start their execution:
[catalog].[create_execution]
[catalog].[set_execution_parameter_value]
[catalog].[start_execution]