每次完成后,一个接一个地运行多个订阅

时间:2013-01-20 10:35:40

标签: tsql reporting-services

我正在尝试以编程方式依次运行一些SSRS订阅。报告都是长时间运行的,并且如果同时触发则一直都会失败。目前,我们有大约四种不同的订阅在一天中分散,确保它们不会发生冲突。不幸的是,这会浪费很多时间。

我对此的解决方案是创建一个未安排在所有每个报告上运行的订阅,然后让每个订阅在每个订阅完成后逐个触发每个订阅:

  1. 一个作业触发第一个订阅
  2. 使用WAITFOR命令为订阅运行提供几秒钟。
  3. 使用WAITFOR命令定期检查订阅是否正在运行('待定')
  4. 当WAITFOR检查发现报告已发送时,作业会触发下一个订阅 等等....
  5. 我知道触发订阅的代码:

    exec [ReportServerWSS].dbo.AddEvent @EventType='SharedSchedule', @EventData='011e83ff-344a-416a-83cb-1a9281e4205b'
    

    我只需要知道如何在检查时使用WAITFOR,然后回复检查结果。

2 个答案:

答案 0 :(得分:1)

根据您问题中的信息,我肯定会说您有XY-problem:您应该真正处理查询和报告的效果和/或locking strategy

话虽如此,如果你坚持通过串行运行报告“解决”问题,我可能不会使用内置订阅,而是寻求更自定义的解决方案,这样你就拥有了你想要的控制权。使用SOAP API创建您自己的应用,脚本或任务,一次调用报表上的Render方法,等待每个报表完成,然后再开始下一个报表。如果您还没有,请将执行超时设置为足够高的值,以使报告顺利完成。

答案 1 :(得分:0)

好的 - 我已经弄明白了:

DECLARE @SubscriptionStatus AS nvarchar(260)


EXEC msdb.dbo.sp_start_job '4B7FA89E-0B56-4ED1-9A0F-37E5D03318CB' /*First long running    report*/
WAITFOR DELAY '00:00:30'

SET @SubscriptionStatus = (SELECT LastStatus FROM Subscriptions Where subscriptionid =    'E156FD91-E7F9-43EC-8B73-28622834EACB')


CheckSubscription1:
    IF @SubscriptionStatus = 'Pending'
    BEGIN
        PRINT 'The First long running Subscription is still running'
        WAITFOR DELAY '00:01:00'
        SET @SubscriptionStatus = (SELECT LastStatus FROM Subscriptions Where     subscriptionid = 'E156FD91-E7F9-43EC-8B73-28622834EACB')
    END

IF @SubscriptionStatus = 'Pending'
    GOTO CheckSubscription1

ELSE

EXEC msdb.dbo.sp_start_job '6D3300BC-ACA9-4EEE-A5F9-546635B585E0' /*Second long running    report*/
WAITFOR DELAY '00:00:30'

SET @SubscriptionStatus = (SELECT LastStatus FROM Subscriptions Where subscriptionid =        'AD54215A-5B7F-48B2-81B2-52C299875AD6')

CheckSubscription2:
    IF @SubscriptionStatus = 'Pending'
    BEGIN
        PRINT 'The second long running Subscription is still running'
        WAITFOR DELAY '00:01:00'
        SET @SubscriptionStatus = (SELECT LastStatus FROM Subscriptions Where     subscriptionid = 'AD54215A-5B7F-48B2-81B2-52C299875AD6')
    END

IF @SubscriptionStatus = 'Pending'
    GOTO CheckSubscription2

ELSE

EXEC msdb.dbo.sp_start_job '84FD876A-1945-405E-A344-6279E27DCD68' /*Third long running     report*/

WAITFOR DELAY '00:00:30'

SET @SubscriptionStatus = (SELECT LastStatus FROM Subscriptions Where subscriptionid =    '8F446935-5450-458F-9076-7AD9FC78D456')

CheckSubscription3:
    IF @SubscriptionStatus = 'Pending'
    BEGIN
        PRINT 'The third long running Subscription is still running'
        WAITFOR DELAY '00:01:00'
        SET @SubscriptionStatus = (SELECT LastStatus FROM Subscriptions Where    subscriptionid = '8F446935-5450-458F-9076-7AD9FC78D456')
    END

IF @SubscriptionStatus = 'Pending'
    GOTO CheckSubscription3

ELSE

PRINT 'All long running report run'

谢谢, UT