我是否可以创建一个Azure Webjob,它将function公开给仪表板但不使用Azure存储?

我想创建一个Azure Webjob来满足批处理需求(特别是它会不断迭代SQL Azure数据库表,获取某些记录,执行一些操作然后更新表)。 我不需要Azure存储。

在这种情况下,我仍然可以将我的方法暴露给Azure函数调用仪表板吗? 或者是Azure存储属性是唯一暴露的方法?

作为一个例子,我可能有一个function:

ShowTotalNumRecordsProcessedToday() 

我希望公开并能够从仪表板调用。 我已经创建了一些公共测试function,但它们没有显示在仪表板中。

我可以在我的场景中这样做吗?

无论您是否使用Azure存储数据,都可以利用WebJobs SDK。

以下是使用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:直接在浏览器中编写代码,这样可能会出现一些错误。

快速回答是:

是的你可以。 您无需与Azure webjobs中的Azure存储进行交互。 我已经实现了一个与SQL Azure数据库交互的处理器。 您可以像使用任何其他webjob一样从仪表板部署和运行它。

希望这可以帮助

更新:确保正确配置连接字符串。 也许这就是问题所在。 另外,如果您要使用网站进行部署,则需要将连接字符串添加到Azure中的网站配置中。

在此处输入图像描述