question

bosko2003414 avatar image
bosko2003414 asked

Get Player in Segment gives internal server error

Basicly what im trying to do is with scheduled task (every hour), run a function in cloudscript that checks every player that has died in a segment (that only saves players with the "deaths" statistic) and adds the number of deaths together and updates the title data "GlobalDeaths".

Im running this code to see if im able to get the players from that segment.

handlers.UpdateGlobalDeaths = function(args) 
{
    var deathCount = 0;
    var resultPlayers = server.GetPlayersInSegment
    ({
                 SegmentId: "1664F484840041B",
                 SecondsToLive: 300,
                 MaxBatchSize: 10000
    });
    var playersInSegmentResult = server.GetPlayersInSegment(resultPlayers);
    log.debug("Total players = " + playersInSegmentResult.playerProfile.length);
}

Everytime i run this through the scheduled task i get this error, any idea what the cause of this is?

There are currently 60 people with "Deaths" of the 68.

"Result": {
        "FunctionName": "UpdateGlobalDeaths",
        "Revision": 29,
        "FunctionResult": null,
        "FunctionResultTooLarge": null,
        "Logs": [
            {
                "Level": "Error",
                "Message": "PlayFab API request failure",
                "Data": {
                    "api": "/Server/GetPlayersInSegment",
                    "request": {
                        "SegmentId": "1664F484840041B",
                        "SecondsToLive": 300,
                        "MaxBatchSize": 10000
                    },
                    "error": "Timeout"
                }
            }
        ],
        "LogsTooLarge": null,
        "ExecutionTimeSeconds": 4.0044373,
        "ProcessorTimeSeconds": 0.002978,
        "MemoryConsumedBytes": 9024,
        "APIRequestsIssued": 1,
        "HttpRequestsIssued": 0,
        "Error": {
            "Error": "InternalServerError",
            "Message": "InternalServerError",
            "StackTrace": "Error\n    at Object.server_request (Script:162:24)\n    at Object.server.GetPlayersInSegment (Script:539:76)\n    at handlers.UpdateGlobalDeaths (B1C57-main.js:86:32)\n    at Object.invokeFunction (Script:117:33)"
        }
    }
PlayStream
10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

For clarification, CloudScript limits the execution time of API calls in CloudScript functions to 4 seconds. If the execution time of the API calls, such as the call of API /Server/GetPlayersInSegment, exceeds 4 seconds, it would return the InternalServerError. For more details, please see this section -- CloudScript timeout error.

[Edited]Did you call the API to get players in the “All Players” segment, then try to retrieve the players that have the profile “’Deaths’:68”? If so, your API call may cause the InternalServerError. We suggest you don’t call the API methods that will be executed for a long time like /Server/GetPlayersInSegment on CloudScript.

Besides, for your case, it’s not necessary for you to call this API /Server/GetPlayersInSegment. Since you call this CloudScript functions with Scheduled Tasks, you can write a judgement method and execute it for “All Players” directly. You can navigate to your title’s [Game Manager]->[Automation]->[Scheduled Tasks], check the [New Scheduled Task] button to open the [New scheduled task] page, then modify the [Type of task] to [Run action on each player in a segment] and choose “All Players” segment to let this task will run actions on all players. If the “Deaths” K/V pair is a public data, you can also consider setting it as a statistic. If so, you can add players in one segment as their statistic values. Please check this documentation -- Player segment configuration for more information about segment configuration.

2 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.

bosko2003414 avatar image bosko2003414 commented ·

I get that, but now im wondering how do I count all the deaths from each player together to update a specific title data? Since first I was using the GetPlayersInSegment and now with the scheduled task I can already give the Segment. But how do I access the data of each player of that segment in the function (inside cloud script) that im calling.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang bosko2003414 commented ·

You can call the API GetPlayersInSegment to get the count of players in a segment. And as the answer said, if you set the [Type of task] as [Run action on each player in a segment] and select “All Players” segment. The Cloud Script function will be run with for all players.

0 Likes 0 ·
Evgeniy avatar image
Evgeniy answered

I have the same problem on 3 of my titles for 2 days. So my games are broken. I am losing players and money :( This is a bad tradition of the playfab to break once a month on live titles.

I gave detailed info in the support task. In particular, I call GetPlayersInSegment from php. Everything worked great for the year before. And keeps on working on my other games. This is definitely a playfab bug.

1 comment
10 |1200

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

Sarah Zhang avatar image Sarah Zhang commented ·

We will discuss your question on your new thread -- GetPlayersInSegment returns 500 Internal Server Error - Playfab Community.

0 Likes 0 ·

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.