question

harsh avatar image
harsh asked

CloudScript objects for storage

Hello,

I have a scenario where an executed cloud script has to post a result to a webhook. In some cases, the post may fail, whether because the url is incorrect or the server hosting the webhook api is temporarily down. Naturally, I'd like to be able to queue this failed post somewhere to try again later (perhaps with a scheduled task). Thus, I tested the following code:

var failedWebhookQueues = [];

handlers.syncTransactions = function (args, context) {
    let hook = context.playStreamEvent.Hook;
    if(!hook)
    {
        log.error("No response url.");
    }
    else
    {
        let content = {TxnId : "TX10222", Status: "Success"};
        let hookResult = http.request(hook, "post", JSON.stringify(content) , "application/json", {owo : "owo", whats : "this"});
        if(!hookResult.includes("200"))
        {
            failedWebhookQueues.push(content);
        }
    }
    return {failedWebhookQueues, hook};
}

After executing this a few times with a wrong webhook, I received this in the function result:

This clearly shows that the array failedWebhookQueues is storing data between cloudscript executions.

My questions are the following:

What is the reliability of this object? Can I expect it to persist between revisions? Could it suddenly be wiped out of memory for no reason? What are the storage limits when using objects like this?

In addition to these questions, you may provide any clarifications deemed necessary.

Could you recommend an alternative storage method that doesn't rely on 3rd party storage?

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

·
Sarah Zhang avatar image
Sarah Zhang answered

This object is not reliable. As this thread -- https://community.playfab.com/questions/39713/is-it-possible-to-set-a-local-variable-as-a-value.html says, CloudScript is static code, and it runs stateless, so you should assume it has no information from previous executions. We tried to test it. The global variables defined by ourselves can’t be returned stably in multiple executions. And it can’t be stored persist between revisions. The external storage is still the reliable solution to store such task queues. If you consider using Azure features, you can use PlayFab’s other Cloud Script feature -- PlayFab CloudScript using Azure Functions. It has better integration with Azure cloud storage.

10 |1200

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

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.