using database in test func, deploying gen 2

This commit is contained in:
Andy Pack 2023-10-12 23:17:50 +01:00
parent 65331501ae
commit becfae98ea
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7
3 changed files with 25 additions and 15 deletions

View File

@ -37,18 +37,20 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 # get source - uses: actions/checkout@v3 # get source
- name: 'Authenticate to Google Cloud' - name: Set up Cloud SDK
uses: 'google-github-actions/auth@v1' uses: google-github-actions/auth@v0.7.3
with: with:
credentials_json: '${{ secrets.GCP_SA_KEY }}' credentials_json: '${{ secrets.GCP_SA_KEY }}'
export_environment_variables: true
create_credentials_file: true
- uses: 'google-github-actions/deploy-cloud-functions@v1' - name: Deploy RunUserPlaylist
with: run: |
name: 'RunUserPlaylist' gcloud functions deploy RunUserPlaylist \
runtime: 'dotnet6' --region europe-west2 \
entry_point: 'Mixonomer.Func.RunUserPlaylist' --gen2 \
source_dir: 'Mixonomer.Func' --runtime=dotnet6 \
env_vars: 'GOOGLE_CLOUD_PROJECT=${{ vars.GCP_PROJECT }}' --trigger-topic RunUserPlaylist \
service_account_email: 'runuserplaylist-func@${{ vars.GCP_PROJECT }}.iam.gserviceaccount.com' --set-env-vars GOOGLE_CLOUD_PROJECT=${{ vars.GCP_PROJECT }} \
event_trigger_type: providers/cloud.pubsub/eventTypes/topic.publish --service-account runuserplaylist-func@${{ vars.GCP_PROJECT }}.iam.gserviceaccount.com
event_trigger_resource: projects/${{ vars.GCP_PROJECT }}/topics/run_user_playlist shell: bash

View File

@ -11,4 +11,8 @@
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" /> <None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mixonomer.Fire\Mixonomer.Fire.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -6,6 +6,7 @@ using CloudNative.CloudEvents;
using Google.Cloud.Functions.Framework; using Google.Cloud.Functions.Framework;
using Google.Events.Protobuf.Cloud.PubSub.V1; using Google.Events.Protobuf.Cloud.PubSub.V1;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Mixonomer.Fire;
namespace Mixonomer.Func 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()}"); _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}");
} }
} }
} }