Mixonomer.NET/Mixonomer.Func/RunUserPlaylist.cs

33 lines
1.0 KiB
C#
Raw Normal View History

2022-08-03 22:51:39 +01:00
using System;
2023-10-12 21:17:32 +01:00
using System.Linq;
2022-08-03 22:51:39 +01:00
using System.Threading;
using System.Threading.Tasks;
using CloudNative.CloudEvents;
using Google.Cloud.Functions.Framework;
using Google.Events.Protobuf.Cloud.PubSub.V1;
using Microsoft.Extensions.Logging;
using Mixonomer.Fire;
2022-08-03 22:51:39 +01:00
namespace Mixonomer.Func;
public class RunUserPlaylist : ICloudEventFunction<MessagePublishedData>
2022-08-03 22:51:39 +01:00
{
private readonly ILogger _logger;
2022-08-03 22:51:39 +01:00
public RunUserPlaylist(ILogger<RunUserPlaylist> logger)
{
_logger = logger;
}
2022-08-03 22:51:39 +01:00
public async Task HandleAsync(CloudEvent cloudEvent, MessagePublishedData data, CancellationToken cancellationToken)
{
_logger.LogInformation($"Received message in C# {data.Message}, {cloudEvent.GetPopulatedAttributes()}");
2022-08-03 22:51:39 +01:00
var userRepo = new UserRepo(projectId: System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT"));
var user = await userRepo.GetUser(data.Message.Attributes["username"]);
_logger.LogInformation($"{user.username} was last refreshed at {user.last_refreshed}");
2022-08-03 22:51:39 +01:00
}
}