78 lines
1.8 KiB
Transact-SQL
78 lines
1.8 KiB
Transact-SQL
USE [HCITools]
|
|
GO
|
|
|
|
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Wait_Random_Time]') AND type in (N'P', N'PC'))
|
|
DROP PROCEDURE [dbo].[Wait_Random_Time]
|
|
GO
|
|
|
|
USE [HCITools]
|
|
GO
|
|
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
CREATE PROCEDURE [dbo].[Wait_Random_Time]
|
|
@in_debug tinyint = 0,
|
|
@in_Minutes smallint
|
|
AS
|
|
/*=============================================================================
|
|
|
|
Explication du traitement realise par la SP
|
|
-------------------------------------------
|
|
La SP sert à attendre un temps aléatoire compris entre 0 et une valeur définie
|
|
|
|
Contexte d'utilisation
|
|
----------------------
|
|
Appelé depuis n'importe quel job
|
|
|
|
Parametres
|
|
----------
|
|
@in_debug : non utilisé
|
|
@in_Minutes : temps maximum en minute
|
|
|
|
Creation : 27.10.16 / FLA
|
|
|
|
Modifications : 28.10.2016 / FLA : Standardisation de la gestion des erreurs
|
|
|
|
=============================================================================*/
|
|
|
|
set nocount on;
|
|
|
|
|
|
/*------------------- Declaration des variables --------------------*/
|
|
|
|
declare @delay int,
|
|
@time datetime,
|
|
@errno int,
|
|
@errmsg varchar(255)
|
|
|
|
|
|
/*------------ Affectation des parametres aux variables ------------*/
|
|
|
|
|
|
|
|
/*-------------------------- Traitement ---------------------------*/
|
|
BEGIN TRY
|
|
|
|
select @delay = rand()* 60 * @in_Minutes
|
|
select @time = dateadd(ss,@delay, '01.01.1900')
|
|
|
|
waitfor delay @time
|
|
|
|
|
|
/*---------------------- Traitement des erreurs ----------------------*/
|
|
END TRY
|
|
BEGIN CATCH
|
|
|
|
/* Traitement des erreurs (avec RaiseError) */
|
|
EXEC dbo.get_Error_Info @in_RaiseError = 1
|
|
|
|
END CATCH
|
|
|
|
GO
|
|
|
|
|