Mixonomer.NET/Mixonomer.Func/RunUserPlaylist.cs

36 lines
1.1 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
2022-08-07 13:54:29 +01:00
namespace Mixonomer.Func
2022-08-03 22:51:39 +01:00
{
public class RunUserPlaylist : ICloudEventFunction<MessagePublishedData>
{
private readonly ILogger _logger;
public RunUserPlaylist(ILogger<RunUserPlaylist> logger)
{
_logger = logger;
}
public async Task HandleAsync(CloudEvent cloudEvent, MessagePublishedData data, CancellationToken cancellationToken)
2022-08-03 22:51:39 +01:00
{
2023-10-12 21:17:32 +01:00
_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
}
}
}