From becfae98ea066a43733f29c1e2c672b88015fa2c Mon Sep 17 00:00:00 2001 From: Andy Pack Date: Thu, 12 Oct 2023 23:17:50 +0100 Subject: [PATCH] using database in test func, deploying gen 2 --- .github/workflows/ci.yml | 26 ++++++++++++++------------ Mixonomer.Func/Mixonomer.Func.csproj | 4 ++++ Mixonomer.Func/RunUserPlaylist.cs | 10 +++++++--- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62e2df0..7997155 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,18 +37,20 @@ jobs: steps: - uses: actions/checkout@v3 # get source - - name: 'Authenticate to Google Cloud' - uses: 'google-github-actions/auth@v1' + - name: Set up Cloud SDK + uses: google-github-actions/auth@v0.7.3 with: credentials_json: '${{ secrets.GCP_SA_KEY }}' + export_environment_variables: true + create_credentials_file: true - - uses: 'google-github-actions/deploy-cloud-functions@v1' - with: - name: 'RunUserPlaylist' - runtime: 'dotnet6' - entry_point: 'Mixonomer.Func.RunUserPlaylist' - source_dir: 'Mixonomer.Func' - env_vars: 'GOOGLE_CLOUD_PROJECT=${{ vars.GCP_PROJECT }}' - service_account_email: 'runuserplaylist-func@${{ vars.GCP_PROJECT }}.iam.gserviceaccount.com' - event_trigger_type: providers/cloud.pubsub/eventTypes/topic.publish - event_trigger_resource: projects/${{ vars.GCP_PROJECT }}/topics/run_user_playlist \ No newline at end of file + - name: Deploy RunUserPlaylist + run: | + gcloud functions deploy RunUserPlaylist \ + --region europe-west2 \ + --gen2 \ + --runtime=dotnet6 \ + --trigger-topic RunUserPlaylist \ + --set-env-vars GOOGLE_CLOUD_PROJECT=${{ vars.GCP_PROJECT }} \ + --service-account runuserplaylist-func@${{ vars.GCP_PROJECT }}.iam.gserviceaccount.com + shell: bash diff --git a/Mixonomer.Func/Mixonomer.Func.csproj b/Mixonomer.Func/Mixonomer.Func.csproj index a7fa119..3460e4b 100644 --- a/Mixonomer.Func/Mixonomer.Func.csproj +++ b/Mixonomer.Func/Mixonomer.Func.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/Mixonomer.Func/RunUserPlaylist.cs b/Mixonomer.Func/RunUserPlaylist.cs index fb1f75f..0f47034 100644 --- a/Mixonomer.Func/RunUserPlaylist.cs +++ b/Mixonomer.Func/RunUserPlaylist.cs @@ -6,6 +6,7 @@ using CloudNative.CloudEvents; using Google.Cloud.Functions.Framework; using Google.Events.Protobuf.Cloud.PubSub.V1; using Microsoft.Extensions.Logging; +using Mixonomer.Fire; namespace Mixonomer.Func { @@ -19,12 +20,15 @@ namespace Mixonomer.Func } - public Task HandleAsync(CloudEvent cloudEvent, MessagePublishedData data, CancellationToken cancellationToken) + public async Task HandleAsync(CloudEvent cloudEvent, MessagePublishedData data, CancellationToken cancellationToken) { - _logger.LogInformation($"Received message in C# {data.Message}, {cloudEvent.GetPopulatedAttributes()}"); - return Task.CompletedTask; + 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}"); } } }