由于 Windows Azure 没有 SQL 代理,您必须创建自己的辅助角色才能像 SQL 代理一样工作,以便安排存储过程的运行。
好吧,除了日期部分之外,我已经准备好这部分了。这应该是非常合乎逻辑的,但在我看来并非如此。那么如何检查今天是否是本月的第一天和一周的第一天。
这是我到目前为止所拥有的:
Trace.WriteLine("SqlWorkerRole entry point called", "Information");
while (true)
{
DateTime firstDayOfMonth = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1, 0, 0, 0);
if (DateTime.UtcNow > firstDayOfMonth)
{
Guid? jobId = StartJob("MonthJob");
if (jobId.HasValue)
{
Trace.WriteLine("Working", "Information");
ExecuteMonthJob();
StopJob(jobId.Value);
}
}
else
{
Thread.Sleep(60000);
}
DateTime firstDayOfWeek = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1, 0, 0, 0);
if (DateTime.UtcNow > firstDayOfWeek)
{
Guid? jobId = StartJob("WeekJob");
if (jobId.HasValue)
{
Trace.WriteLine("Working", "Information");
ExecuteWeekJob();
StopJob(jobId.Value);
}
}
else
{
Thread.Sleep(60000);
}
}
我需要这部分的帮助(每月的第一天)
DateTime firstDayOfMonth = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1, 0, 0, 0);
if (DateTime.UtcNow > firstDayOfMonth)
和(一周的第一天)
DateTime firstDayOfWeek = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1, 0, 0, 0);
if (DateTime.UtcNow > firstDayOfWeek)