您可以利用WebJobs SDK,無論您是否使用Azure存儲數據或不。
下面是一個使用SDK進行記錄,但沒有別的工作的一個例子:
public static void Main
{
using(JobHost host = new JobHost())
{
// Invoke the function from code
host.Call(typeof(Program).GetMethod("DoSomething"));
// The RunAndBlock here is optional. However,
// if you want to be able to invoke the function below
// from the dashboard, you need the host to be running
host.RunAndBlock();
// Alternative to RunAndBlock is Host.Start and you
// have to create your own infinite loop that keeps the
// process alive
}
}
// In order for a function to be indexed and visible in the dashboard it has to
// - be in a public class
// - be public and static
// - have at least one WebJobs SDK attribute
[NoAutomaticTrigger]
public static void DoSomething(TextWriter log)
{
log.WriteLine("Doing something. Maybe some SQL stuff?");
}
但是,您將需要一個存儲帳戶連接主機和儀表板。
你也可以創建自己的「自定義觸發」 SQL或其他任何類似這樣的:
public static void Main
{
using (JobHost host = new JobHost())
{
host.Start();
while (!TerminationCondition)
{
if (SomeConditionRequiredForTheTrigger)
{
host.Call(typeof(Program).GetMethod("DoSomething"));
}
Thread.Sleep(500);
}
host.Stop();
}
}
// In order for a function to be indexed and visible in the dashboard it has to
// - be in a public class
// - be public and static
// - have at least one WebJobs SDK attribute
[NoAutomaticTrigger]
public static void DoSomething(TextWriter log)
{
log.WriteLine("Doing something. Maybe some SQL stuff?");
}
PS:直接在瀏覽器編寫的代碼,從而可能有一些錯誤。
+1爲偉大的第二個例子!我已經意識到獲取函數索引並顯示在儀表板中的要求(如您在第二個示例中的註釋中所述) - > https://stackoverflow.com/questions/25811659/can-i-create-an-azure- webjob - 即-自曝函數對的儀表板,但-犯規/ 25819212?iemail = 1&noredirect = 1#comment40378135_25811820 – Emilio 2014-09-13 17:05:45
我標記了你接受的答案,因爲你是第一位的,你的回答是正確的,但是你能給你的答案添加Lopez提到的有關連接字符串的要求嗎? – Emilio 2014-09-22 22:22:54
您在顯示板中爲函數進行索引的明確資格列表是一個很棒的筆記,也是我在任何Azure WebJob SDK文檔中都沒有找到的筆記。非常感謝。 – BradV 2016-09-30 17:51:12