question

matt-6 avatar image
matt-6 asked

Azure Functions - ScheduledTaskFunctionExecutionContext

Hi, so I'm converting things across from cloudscript to azure functions and I've a question about the context model.

For functions called from the client I'm using the method in the github example project to create the function context, and then a server api instance:

// using HttpRequestMessage requestvar context = await FunctionContext<T>.Create(request);

Settings.TrySetSecretKey(context.ApiSettings);

var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext);

As far as I can see there's no equivalent Create for the scheduled Task Function Execution Context, so how do I go about creating a server api instance in this case?

// HttpRequest req
ScheduledTaskFunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<ScheduledTaskFunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());

What's the step I'm missing?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Hernando avatar image
Hernando answered

Are you confused about how to generate PlayFabServerInstanceAPI from ScheduledTaskFunctionExecutionContext? You can try the following code in C# SDK:

var apiSettings = new PlayFabApiSettings   
{  
	TitleId = context.TitleAuthenticationContext.Id, 
	DeveloperSecretKey =
	Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY",EnvironmentVariableTarget.Process),  

};   

var serverApi = new PlayFabServerInstanceAPI(apiSettings);

As you've set TitleID and dev key in Azure portal, you should be able to get dev key with "GetEnvironmentVariable" method, but you may need to change the key to match your setting.

8 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

matt-6 avatar image matt-6 commented ·

Thanks, that's exactly what I'm looking for. Could you point me in the direction of the c# sdk, I haven't found much documentation tbh.

0 Likes 0 ·
Hernando avatar image Hernando matt-6 commented ·

Check out C# SDK documentation here: https://docs.microsoft.com/en-us/gaming/playfab/sdks/c-sharp/quickstart. Besides, if you are writing code for Azure Function this turorial will be helpful for you: https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/cloudscript-af-context

0 Likes 0 ·
matt-6 avatar image matt-6 Hernando commented ·

Thanks, but I've already seen those. I was rather hoping there was something I'd missed.

0 Likes 0 ·
matt-6 avatar image matt-6 commented ·

Have you got this working with scheduled tasks? Event with setting up the api settings as you've shown I still get an error about the developer secret key being missing when trying to access title data.

0 Likes 0 ·
Hernando avatar image Hernando matt-6 commented ·

You should assign your own Secret Key to the DeveloperSecretKey property. To obtain it, navigate to [Game Manager] ->[Title Settings]->[Secret Keys].

0 Likes 0 ·
matt-6 avatar image matt-6 Hernando commented ·

I have. I have no issues running functions called from the client, but I am running into this issue running a scheduled task.

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.