You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT @CURRENT_TIMESTAMP = (SELECT CAST(SYSDATETIME() AS VARCHAR(19)))
68
+
SELECT @NUMBER_OF_QUEUED_PROCESSES = (SELECT COUNT(*) AS NUMBER_OF_QUEUED_PROCESSED FROM [900_Direct_Framework].[omd_processing].[vw_QUEUE_BATCH_PROCESSING])
69
+
70
+
IF @DEBUG_FLAG = 1 PRINT ''@NUMBER_OF_RUNNING_PROCESSES= ''+CAST (@NUMBER_OF_RUNNING_PROCESSES AS VARCHAR(10))
71
+
IF @DEBUG_FLAG = 1 PRINT ''@MAX_CONCURRENCY= ''+CAST (@MAX_CONCURRENCY AS VARCHAR(10))
72
+
IF @DEBUG_FLAG = 1 PRINT ''@CURRENT_TIMESTAMP = ''+ @CURRENT_TIMESTAMP
73
+
IF @DEBUG_FLAG = 1 PRINT ''@NUMBER_OF_QUEUED_PROCESSES = ''+ +CAST (@NUMBER_OF_QUEUED_PROCESSES AS VARCHAR(10))
74
+
75
+
--Whenever the number of jobs exceeds the parameter, wait for a bit (as per the delay time)
76
+
WHILE (@NUMBER_OF_RUNNING_PROCESSES >= @MAX_CONCURRENCY)
77
+
BEGIN
78
+
IF @DEBUG_FLAG =1
79
+
BEGIN
80
+
SET @PRINT_MESSAGE = ''WAITFOR ''+@DELAY_TIME+'', currently still @NUMBER_OF_RUNNING_PROCESSES at ''+CAST (@NUMBER_OF_RUNNING_PROCESSES AS VARCHAR(10))
81
+
RAISERROR (@PRINT_MESSAGE, 0, 1) WITH NOWAIT; -- Raise Error used to flush to the debug window immediately, PRINT has a large delay
82
+
END
83
+
84
+
WAITFOR DELAY @DELAY_TIME -- Perform the wait / delay.
85
+
EXEC #runningJobs @NUMBER_OF_RUNNING_PROCESSES OUTPUT -- Check again if the next process is good to g.
86
+
END
87
+
88
+
IF @DEBUG_FLAG =1 PRINT ''After wait @NUMBER_OF_RUNNING_PROCESSES= ''+CAST (@NUMBER_OF_RUNNING_PROCESSES AS VARCHAR(10))
89
+
IF @DEBUG_FLAG =1 PRINT ''After wait @MAX_CONCURRENCY= ''+CAST (@MAX_CONCURRENCY AS VARCHAR(10))
90
+
IF @DEBUG_FLAG =1 PRINT ''After wait @CURRENT_TIMESTAMP = ''+ @CURRENT_TIMESTAMP
91
+
92
+
-- When a spot becomes available, run the process from the queue
93
+
SELECT TOP 1 @PROCESS_NAME = BATCH_CODE
94
+
FROM
95
+
(
96
+
-- Select the Batch that hasn''t run the longest (oldest age)
97
+
SELECT BATCH_CODE, END_DATETIME
98
+
FROM [900_Direct_Framework].[omd_processing].[vw_QUEUE_BATCH_PROCESSING]
99
+
) batchQueue
100
+
ORDER BY END_DATETIME ASC
89
101
90
-
SET @PRINT_MSG = ''EXECUTING JOB: ''+@JOBNAME
91
-
92
-
IF @DEBUG_FLAG =1 RAISERROR (@PRINT_MSG, 0, 1) WITH NOWAIT
SET @JOBNAME = SUBSTRING(@JOBNAME,1,LEN(@JOBNAME)-5)
103
-
SET @SQL_STRING = N''UPDATE [900_Direct_Framework].omd.BATCH SET INACTIVE_INDICATOR=''''Y'''' WHERE BATCH_CODE=''''''+@JOBNAME+''''''''
104
-
SET @PRINT_MSG = ''ERROR EXECUTING JOB: ''+@JOBNAME+''.dtsx. DEACTIVATE QUERY: ''+@SQL_STRING+''''
105
-
RAISERROR (@PRINT_MSG, 0, 1) WITH NOWAIT
106
-
EXECUTE sp_executesql @SQL_STRING
107
-
END CATCH
108
-
109
-
--Also functions as delayer
110
-
WAITFOR DELAY ''00:00:05'' -- This is mandatory! Otherwise processes will be spawned too fast! This prevents the same process to be kicked off many times before OMD has had the chance to register
102
+
SET @PRINT_MESSAGE = ''Running process: ''+@PROCESS_NAME
103
+
104
+
IF @DEBUG_FLAG =1 RAISERROR (@PRINT_MESSAGE, 0, 1) WITH NOWAIT
105
+
BEGIN TRY
106
+
EXEC [900_Direct_Framework].[omd].[RunBatch]
107
+
@BatchCode = @PROCESS_NAME
108
+
END TRY
109
+
BEGIN CATCH
110
+
SET @PROCESS_NAME = SUBSTRING(@PROCESS_NAME,1,LEN(@PROCESS_NAME)-5)
111
+
SET @SQL_STRING = N''UPDATE [900_Direct_Framework].omd.BATCH SET INACTIVE_INDICATOR=''''Y'''' WHERE BATCH_CODE=''''''+@PROCESS_NAME+''''''''
112
+
SET @PRINT_MESSAGE = ''ERROR EXECUTING JOB: ''+@PROCESS_NAME+'' DEACTIVATE QUERY: ''+@SQL_STRING+''''
113
+
RAISERROR (@PRINT_MESSAGE, 0, 1) WITH NOWAIT
114
+
EXECUTE sp_executesql @SQL_STRING
115
+
END CATCH
116
+
117
+
-- Also functions as delayer
118
+
-- This is mandatory! Otherwise processes will be spawned too fast! This prevents the same process to be kicked off many times before OMD has had the chance to register
119
+
WAITFOR DELAY ''00:00:05''
111
120
END
112
-
DROP PROCEDURE #runningJobs
113
-
',
114
-
@database_name=N'master',
115
-
@output_file_name=N'D:\Logs\Job_Master',
116
-
@flags=2
121
+
122
+
DROP PROCEDURE #runningJobs',
123
+
@database_name=N'master',
124
+
@output_file_name=N'D:\Logs\Job_Master',
125
+
@flags=2
117
126
IF (@@ERROR<>0OR @ReturnCode <>0) GOTO QuitWithRollback
0 commit comments