Skip to content

Instantly share code, notes, and snippets.

@yuka1984
Created October 18, 2017 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuka1984/7cf65d1725bdb6e9c871017655d54deb to your computer and use it in GitHub Desktop.
Save yuka1984/7cf65d1725bdb6e9c871017655d54deb to your computer and use it in GitHub Desktop.
public static class TriggerTest1
{
private static Lazy<Guid> lazyDateTime = new Lazy<Guid>(() => Guid.NewGuid());
[Singleton]
[FunctionName("TriggerTest1")]
public static async Task Run1(
[QueueTrigger("Test1", Connection = "AzureWebJobsStorage")]string myQueueItem
, ExecutionContext context
, [Table("Test1", Connection = "AzureWebJobsStorage")] CloudTable table
, TraceWriter log)
{
await Run(myQueueItem, context, table, log);
}
[Singleton(Mode = SingletonMode.Listener)]
[FunctionName("TriggerTest2")]
public static async Task Run2(
[QueueTrigger("Test2", Connection = "AzureWebJobsStorage")]string myQueueItem
, ExecutionContext context
, [Table("Test2", Connection = "AzureWebJobsStorage")] CloudTable table
, TraceWriter log)
{
await Run(myQueueItem, context, table, log);
}
[FunctionName("TriggerTest3")]
public static async Task Run3(
[QueueTrigger("Test3", Connection = "AzureWebJobsStorage")]string myQueueItem
, ExecutionContext context
, [Table("Test3", Connection = "AzureWebJobsStorage")] CloudTable table
, TraceWriter log)
{
await Run(myQueueItem, context, table, log);
}
private static async Task Run(
string myQueueItem
, ExecutionContext context
, CloudTable table
, TraceWriter log)
{
await table.CreateIfNotExistsAsync();
var insertOperation = TableOperation.Insert(new Result()
{
PartitionKey = lazyDateTime.Value.ToString("N"),
RowKey = string.Format("{0:D3}", int.Parse(myQueueItem)),
InvocationId = context.InvocationId.ToString("N"),
Time = DateTime.UtcNow.AddHours(9).ToLongTimeString()
});
await table.ExecuteAsync(insertOperation);
Thread.Sleep(1000);
}
public class Result : TableEntity
{
public string Time { get; set; }
public string InvocationId { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment