计划任务和Sql Azure的? [英] Scheduled Tasks with Sql Azure?

查看:126
本文介绍了计划任务和Sql Azure的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有使用计划任务与SQL Azure的一种方式?
每一个帮助AP preciated。

I wonder if there's a way to use scheduled tasks with SQL Azure? Every help is appreciated.

问题的关键是,我想每天运行一个简单的,单一的行语句,并想prevent建立一个辅助角色。

The point is, that I want to run a simple, single line statement every day and would like to prevent setting up a worker role.

推荐答案

有没有SQL代理相当于今天的SQL Azure上。你必须从一个后台任务打电话给你的单行语句。但是,如果你有一个Web角色已经,您可以轻松地生成一个线程在你的Web角色来处理这个,而无需创建一个工作者角色。我在博客这个概念这里。产生一个线程,则可以做到这一点在的OnStart()的事件处理程序(其中角色实例没有添加到负载平衡器),或在运行()方法(其中角色实例已被添加到负载平衡器)。通常这是一个好主意,做安装在的OnStart()。

There's no SQL Agent equivalent for SQL Azure today. You'd have to call your single-line statement from a background task. However, if you have a Web Role already, you can easily spawn a thread to handle this in your web role without having to create a Worker Role. I blogged about the concept here. To spawn a thread, you can either do it in the OnStart() event handler (where the Role instance is not yet added to the load balancer), or in the Run() method (where the Role instance has been added to the load balancer). Usually it's a good idea to do setup in the OnStart().

有一点需要注意,可能不是很明显,无论您在自己的工作角色,或在现有Web角色的后台线程执行这个调用:如果您扩展您的角色,比方说,两个实例,你需要确保每天通话只能从其中一个实例发生(否则你可能最终与重复两种,或者正在执行一个可能,代价高昂的操作多次)。还有,你可以用它来避免这种情况,一些技术,如表行锁或Azure存储BLOB租约。同前,则可以使用该行来存储的被执行的操作的最后时间的时间戳。如果您获得了锁,你可以检查,看是否发生了设置的时间窗口(也许一个小时?)内的操作,以决定是否对其他实例中的一个已经被执行了。如果无法获取锁,你可以假设另一个实例都有锁,并执行命令。还有其它技术 - 这只是一个想法

One caveat that might not be obvious, whether you execute this call in its own worker role or in a background thread of an existing Web Role: If you scale your Role to, say, two instances, you need to ensure that the daily call only occurs from one of the instances (otherwise you could end up with either duplicates, or a possibly-costly operation being performed multiple times). There are a few techniques you can use to avoid this, such as a table row-lock or an Azure Storage blob lease. With the former, you can use that row to store the timestamp of the last time the operation was executed. If you acquire the lock, you can check to see if the operation occurred within a set time window (maybe an hour?) to decide whether one of the other instances already executed it. If you fail to acquire the lock, you can assume another instance has the lock and is executing the command. There are other techniques - this is just one idea.

这篇关于计划任务和Sql Azure的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆