按计划为WebJob动态命名Blob

时间:2015-01-27 00:36:08

标签: azure-webjobs azure-webjobssdk

我有一个Web作业,它根据WebClient调用的返回值创建一个blob。这工作正常。但是从Blob属性中可以看到(参见下面的代码),该文件的名称是静态的。因此,每次在blob存储中都会被覆盖。

功能类:

public class Functions
{
    private static int _retryCount;
    private static readonly int _retryLimit = int.Parse(ConfigurationManager.AppSettings["retryLimit"]);
    private static readonly string _ghostRestfullUri = ConfigurationManager.AppSettings["ghostRestfullUri"];

    [NoAutomaticTrigger]
    public static void LightUpSite([Blob("ghost/response.json")] out string output, TextWriter logger)
    {
        _retryCount = 0;
        output = string.Empty;

        do
        {
            try
            {
                using (var request = new WebClient())
                {
                    var response = request.DownloadString(_ghostRestfullUri);

                    _retryCount++;

                    output = response;

                    break;
                }
            }
            catch(Exception exception)
            {
                logger.WriteLine("Job failed. Retry number:{0}", _retryCount);
            }

        } while (_retryCount < _retryLimit);
    }
}

主菜单:

public class Program
{
    static void Main()
    {
        var host = new JobHost();

        host.Call(typeof(Functions).GetMethod("LightUpSite"));
    }
}

如何使用占位符动态命名传入文件?

我已经尝试了以下内容:

  1. ghost / {name}
  2. 鬼/ {BlobName}
  3. 需要注意的其他事项:

    此作业按计划运行,因此主机不会运行和阻止 触发器不会调用此作业,它只是唤醒并运行; 因为源不是来自消息队列对象或上传的文件,所以我无法弄清楚我应该如何命名这个blob。

    也许以某种方式直接使用blob存储API?

1 个答案:

答案 0 :(得分:1)

  1. 要动态命名输出blob,请使用IBinder示例
  2. 中显示的Host.Call
  3. 要像来自static void Main() { var host = new JobHost(); host.Call(typeof(Functions).GetMethod("LightUpSite"), new {blobArgumentName= "container/blob"}); } 的调用一样动态命名输入blob,只需将blob的名称作为参数传递:

    {{1}}
相关问题