Skip to content

Instantly share code, notes, and snippets.

@johndownskloud
Created September 7, 2017 03:35

Revisions

  1. johndownskloud created this gist Sep 7, 2017.
    27 changes: 27 additions & 0 deletions FunctionV1.csx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #r "Microsoft.WindowsAzure.Storage"

    using System;
    using Microsoft.WindowsAzure.Storage;

    public static void Run(TimerInfo myTimer, TraceWriter log)
    {
    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");

    // connect to Azure Storage
    var connectionString = System.Configuration.ConfigurationManager.AppSettings["AzureWebJobsStorage"];
    var account = CloudStorageAccount.Parse(connectionString);
    var queueClient = account.CreateCloudQueueClient();

    // check the length of each queue
    var queueNames = new string[] { "processorders", "processorders-poison" };
    foreach (var queueName in queueNames)
    {
    // get a reference to the queue and retrieve the queue length
    var queue = queueClient.GetQueueReference(queueName);
    queue.FetchAttributes();
    var length = queue.ApproximateMessageCount;

    // log the length
    log.Info($"{queueName}: {length}");
    }
    }