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

相关文章

Microsoft云包括了Azure、PowerPlatform、Microsoft365、Git...
《WindowsAzurePlatform系列文章目录》 我们在使用AzureAPI...
微软免费使用一年的Azure虚拟机,默认提供了一个64G的磁盘,...
上篇请访问这里做一个能对标阿里云的前端APM工具(上)样本多...
一年一度的MicrosoftBuild终于来了,带来了非常非常多的新技...