如何在ssis包中获取当前正在运行的任务的名称

时间:2017-09-17 04:12:43

标签: ssis

我在SSIS包中按顺序执行了四个任务。如何在每10分钟后获取当前正在运行的任务的名称?

1 个答案:

答案 0 :(得分:0)

以下是可用于使用SQL作业代理获取正在运行的package_name的脚本。然后,您可以创建一个ssis包来提取此数据,然后在每10分钟运行一次的SQL JOB代理中进行设置。您可以在message_source_name

中看到任务名称

当前正在运行的包含taskname:

USE SSISDB
GO
/*
Configuration
*/
    -- Filter data by execution id (use NULL for no filter)

-- Show only Child Packages or everyhing
DECLARE @showOnlyChildPackages BIT = 0;
-- Show only message from a specific Message Source
DECLARE @messageSourceName NVARCHAR(MAX)= '%'

-- Filter data by project name (use % for no filter)
DECLARE @projectNamePattern NVARCHAR(100) = '%'
-- Filter data by package name (use % for no filter)
DECLARE @packageNamePattern NVARCHAR(100) = '%'
-- Filter data by execution id (use NULL for no filter)
DECLARE @executionIdFilter BIGINT = NULL;
with running as (

/*
Implementation
*/
-- Show last 15 executions
SELECT TOP 15
e.execution_id, 
e.project_name,
e.package_name,
e.project_lsn,
e.status, 
status_desc = CASE e.status 
WHEN 1 THEN 'Created'
WHEN 2 THEN 'Running'
WHEN 3 THEN 'Cancelled'
WHEN 4 THEN 'Failed'
WHEN 5 THEN 'Pending'
WHEN 6 THEN 'Ended Unexpectedly'
WHEN 7 THEN 'Succeeded'
WHEN 8 THEN 'Stopping'
WHEN 9 THEN 'Completed'
END,
e.start_time,
e.end_time,
elapsed_time_min = datediff(mi, e.start_time, e.end_time)
FROM 
catalog.executions e 
WHERE 
e.project_name LIKE @projectNamePattern
AND
e.package_name LIKE @packageNamePattern
AND
e.execution_id = ISNULL(@executionIdFilter, e.execution_id)
and e.status = 2


)



select * from running a 
inner join 
(
    SELECT top 1 * FROM catalog.event_messages em 
WHERE ((em.operation_id = @executionIdFilter) OR @executionIdFilter IS NULL) 
--AND (em.event_name IN ('OnInformation', 'OnError', 'OnWarning'))
AND (package_path LIKE CASE WHEN @showOnlyChildPackages = 1 THEN '\Package' ELSE '%' END)
AND (em.message_source_name like @messageSourceName)
order by operation_id desc,message_time desc
)
 b on a.execution_id = b.operation_id