微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

作为一个例子,我可能有一个功能

ShowTotalNumRecordsProcessedToday()

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

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

解决方法:

无论是否使用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:直接在浏览器中编写代码,因此可能会出现一些错误.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐