Custom Code Rank Backup

0 votes

Hi, Himanshu Sharma Rankings error occurs during storage. Could you tell me how effective?

Error Message

Status: 400

Output: {"failure" : "true", "message" : {"app42Fault":{"httpErrorCode":400,"appErrorCode":1904,"message":"Bad Request","details":" Application Exception : Request Execution Time Exceeded threashold value "}}, "errorCode":400}
public class RankBackupAll implements Executor 
{
private ServiceAPI sp = new ServiceAPI( Constants.App42ApiKey, Constants.App42ApiSecret);
private final int HTTP_STATUS_SUCCESS = 200;
private String moduleName = "RankBackupAll";
 
@Override
public HttpResponseObject execute(HttpRequestObject request) 
{
GameService gameService = sp.buildGameService();
ScoreBoardService scoreBoardService = sp.buildScoreBoardService();
StorageService storageService = sp.buildStorageService();
        int max = 50;
 
        List<Game> games = gameService.getAllGames();
        for( int i=0; i<games.size(); i++)
        {
        String gamename = games.get(i).getName();
        try{
        JSONObject j = new JSONObject();
j.put(gamename, gamename);
j.put("CNT", 0);
try{
Game game = scoreBoardService.getTopNRankers( gamename, max);
j.put("CNT", game.getScoreList().size());
for (int g = 0; g < game.getScoreList().size(); g++)
{
Storage st = storageService.findDocumentByKeyValue("WW1DB", "Users", "UUID", game.getScoreList().get(g).getUserName() );
               
JSONObject js = new JSONObject(st.getJsonDocList().get(0).getJsonDoc());
j.put("nick"+g, js.get("nick"));
j.put("Lan"+g, js.getString("Lan"));
j.put("score"+g, game.getScoreList().get(g).getValue());
}
}catch (App42Exception ee)
                {}
try{
storageService.updateDocumentByKeyValue( "WW1DB", "Ranks", gamename, gamename, j );
}catch(App42Exception e){
storageService.insertJSONDocument( "WW1DB", "Ranks", j );
}
                } catch (JSONException e) {}
}
JSONObject jsonResponse = new JSONObject();
try {
jsonResponse.put("moduleName",  moduleName );
} catch (JSONException e) {
}
return new HttpResponseObject(HTTP_STATUS_SUCCESS, jsonResponse);
}
}
asked Jan 15, 2016 in App42 Cloud API-BaaS by airfighter.pilot (10 points)

1 Answer

0 votes

Hello, 

 

Thanks for sharing the code snippet and the error message with us. This exception mainly occurs when your request is not able to process within given timeframe.  There is limit of 10 seconds to complete your activity in custom code. If your request doesn't complete in 10 seconds, it will automatically return with Execution Time Exceeded error.

However in order to resolve this, I would like to understand the complete use case of getting all games inside the custom code and updating storage basis on 50 top rankers. 

Regards,

Himanshu Sharma

answered Jan 15, 2016 by hs00105 (2,005 points)
Hi Sharma,

I wanted to import user information above top 50 rank.
             int max = 50;
             Query query = QueryBuilder.Build ("UUID", "", Operator.GREATER_THAN);
             App42API.SetDbName ("WW1DB");
             App42API.Initialize (Constant.Instance.apiKey, Constant.Instance.secretKey);
             scoreBoardService = App42API.BuildScoreBoardService ();
             scoreBoardService.SetQuery ("Users", query);
             scoreBoardService.GetTopNRankings ("ww1-global-all", max, callBackAllRank = new ScoreBoardResponseAllRank ());

But it took too much time.

So back up the rankings and at regular intervals.

I want to bring quick ranking.

Thank you.
Hi,  

Just wanted to know that how much time GetTopNRankings method is taking for the result. It will help us to provide better support to you and if possible then please share your app name, game name with us at support@shephertz.com.

Apart from this, making this amount of calls through custom code is not possible because, in custom code your program will automatically shutdown after 10 seconds. If you want to run this backup process, then I will recommend you to have a look at App42 PaaS where you can deploy your java code and run this task as much as you want. Please have a look at this(http://app42paas.shephertz.com/) link and let me know if you need any help while integrating it.
 
Regards,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...