简体   繁体   English

动态调度数据驱动的订阅

[英]Dynamic scheduling of data driven subscription

I have a data driven subscription which delivers a report to an email alias at specific time. 我有一个数据驱动的订阅,可以在特定时间将报告发送到电子邮件别名。 In a subscription query: 在订阅查询中:

select WorkProjectionReportTime,WorkProjectionReportToMailAlias,
'Work Projection Report for the period ' + CONVERT(varchar(10),GETDATE()-31,101)+ ' to '+CONVERT(varchar(10),GETDATE()-1,101) as Subject,
CONVERT(varchar(10),GETDATE()-31,101) as FromDate,CONVERT(varchar(10),GETDATE()-1,101) as ToDate, 60 as WO, 
'Please see the attachment for the details' as body
from tblConfig
Pivot ( MAX(cValue) for cKey in (WorkProjectionReportTime,WorkProjectionReportToMailAlias) ) as xyz

So by query I get all the required fields, Email To, Time, report parameters. 因此,通过查询,我得到了所有必填字段,电子邮件发送至,时间,报告参数。

I want to use the time parameter to schedule report. 我想使用时间参数来安排报告。 eg if time is 9:30 the report should be mailed at 9:30 AM etc. I want to achieve this from SQL or database front and not from C#. 例如,如果时间是9:30,则报告应在9:30 AM寄出,以此类推。我想从SQL或数据库方面而不是从C#中实现这一点。 How to achieve this? 如何实现呢?

Combined with a scheduling table suggested above, you can use the following to send a report via TSQL, using @report_path as your parameter: 结合上面建议的调度表,可以使用以下命令通过TSQL以@report_path作为参数来发送报告:

SELECT 'exec ReportServer.dbo.AddEvent @EventType=''TimedSubscription'', 
             @EventData=''' + CONVERT(VARCHAR(max), rs.SubscriptionID) + ''''
FROM   ReportServer.dbo.Catalog c,
       ReportServer.dbo.ReportSchedule rs,
       ReportServer.dbo.Schedule s
WHERE      rs.ReportID = c.ItemID
       AND rs.ScheduleID = s.ScheduleID
       AND c.path = @report_path
       AND s.RecurrenceType = 1 -- only the ones with the regular scheduling disabled

You can create job that runs each minute and checks whether there are reports to send and sends them. 您可以创建每分钟运行的作业,并检查是否有要发送和发送的报告。 But it means that you will have delay of maximum 1 minute + "how long it takes for your report to run". 但这意味着您将最多延迟1分钟+“报表运行需要多长时间”。

Further more 更进一步

  1. you can put report sending in service Broker and it will make sure that reports are sent asynchronously to your schedule checker job. 您可以将报告发送放入Service Broker中,这样可以确保将报告异步发送到计划检查器作业。

or 要么

  1. Create queuing table for report sending, and main job will insert send requests to it. 创建用于发送报告的排队表,主作业将向其插入发送请求。 Additionally you can have 5 jobs that read 1-2 requests and sends them, but in this case you delay as job schedule. 此外,您可以有5个作业读取1-2个请求并将其发送,但是在这种情况下,您将延迟作工时间表。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM