Tye is a tool that makes developing, testing, and deploying microservices and distributed applications easier. Project Tye includes a local orchestrator to make developing microservices easier and the ability to deploy microservices to Kubernetes with min
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

57 lines
1.9 KiB

using System;
using System.Threading.Tasks;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Dapper;
using Npgsql;
namespace worker_function
{
public class QueueTrigger
{
private readonly IConfiguration _configuration;
public QueueTrigger(IConfiguration configuration)
{
_configuration = configuration;
}
[FunctionName("QueueTrigger")]
public async Task Run([QueueTrigger("test-queue", Connection = "AzureWebJobsStorage")]string data, ILogger log)
{
log.LogInformation(_configuration.GetConnectionString("postgres"));
using (var connection = new NpgsqlConnection(_configuration.GetConnectionString("postgres")))
{
var vote = JsonSerializer.Deserialize<Vote>(data);
// TODO
connection.Open();
await connection.ExecuteAsync(@"CREATE TABLE IF NOT EXISTS votes (
Id VARCHAR(255) NOT NULL UNIQUE,
Vote VARCHAR(255) NOT NULL);");
var command = @"INSERT INTO votes (Id, Vote) VALUES (@voterId, @vote)
ON CONFLICT (Id)
DO UPDATE SET Vote = @vote";
await connection.ExecuteAsync(command, vote);
}
log.LogInformation($"C# Queue trigger function processed: {data}");
}
public class Vote
{
public Guid voterId { get; set; }
public string vote { get; set; }
}
public class VoteCount
{
public string Vote { get; set; }
public int Count { get; set; }
}
}
}