Idea

brendan avatar image
brendan suggested

Cron-job like feature

10 |1200

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

2 Comments

·
brendan avatar image
brendan commented

cetorr
started a topic on Wed, 11 February 2015 at 6:18 AM

Is it possible to create a piece of code which is then executed on a daily or weekly basis? LIke a cron job would do?

I would like to send mails to players when some conditions are met.

Is this possible in the current version of playfab?

Thanks in advance.


19 Comments
johntube said on Wed, 11 February 2015 at 5:04 PM

I got a similar need, I need some CloudScript Action to be triggered on specific events like new user creation or user login etc.


Brendan Vanous said on Wed, 11 February 2015 at 8:11 PM

@cetorr

Right now, no. The intent is that any admin-type operations you need to perform would be best managed locally by the developer, calling into the Admin or Server API calls in order to accomplish the task. In this case, what causes the conditions to be met? If there's an action being taken by a player somewhere, simply calling a Cloud Script at that time would be the way to go.

@johntube

Can you explain how this would differ from simply calling the Cloud Script handlers from the client, when the user signs in?


johntube said on Wed, 11 February 2015 at 8:33 PM

It's a matter of where you put the "simply" because if you want to call a CloudScript action when a user logs in with facebook/Google/etc. for the first time and you got the NewlyCreated set to true in the login callback you still need to call GetCloudScriptUrl and have a field where you store the NewlyCreated value because you can only call that CloudScript action in the OnGetCloudScriptUrl callback !


Brendan Vanous said on Wed, 11 February 2015 at 8:43 PM

If the difference is between having a state definition in the title itself, which lets you know to call an "onFirstTimePlayer" handler once your player is signed in and you've had a chance to call GetCloudScriptUrl (which you only need to do once after sign-in, to be clear), versus defining a condition in PlayFab and a handler which is called as a result, I'm not seeing any real savings. It seems like you would be doing the same work defining the condition and action, just in a tool in the PlayFab Game Manager rather than in code in the title itself.


johntube said on Wed, 11 February 2015 at 8:56 PM

Ok I'm convinced. Sorry for sounding too lazy to code. Thanks anyway.


Brendan Vanous said on Wed, 11 February 2015 at 9:24 PM

Not a problem at all! :)


cetorr said on Thu, 12 February 2015 at 1:02 AM

Thanks Brendan for the quick reply. It's a pity though, I really need this feature. It's not that the game should call the script when something is met, it's the server who should check daily whether users completed tasks or not (like a cron job can).

Currently I'm doing research on backend platforms for our company and this feature is one of the requirements. I'll hear from you if or when there is a solution or work-around.

Cheers.


Brendan Vanous said on Thu, 12 February 2015 at 1:53 PM

There are two ways to accomplish this, based upon your goals.

If what you need is a report that lists the segment of users who have performed some behavior you can identify using events (https://api.playfab.com/Documentation/Client/method/LogEvent), you could use our analytics system to accomplish this. We have an integration with Appuri which allows any Premium tier developer to use their suite of tools to identify segments, behaviors, etc., and then take action on those users. We have this built into our Push Notification service in PlayFab now, so that you can push messages to specific segments, for example.

Alternately, if what you want to do is identify some specific actions/behaviors for which you want to award something to users, it's far more efficient to do that as part of a logic check when that user is online (or a user linked to that user, if it needs to be reflected in a friends/clan system). By the nature of the logic, that spreads the load out across time as users sign into the service. We do this right now for our regenerating currency logic, as a specific example. We're not walking through every user in a game and incrementing their currencies every second. Instead, when a user performs any action which involves the balance of that currency (checking the total, trying to spend it, etc.), we calculate the current balance based upon elapsed time. You would essentially do the same here, computing what to grant a player when they sign in or check inventory.


cetorr said on Fri, 13 February 2015 at 4:02 AM

Thank you for the extensive and valuable info Brendan. I'm pleased to hear these types of efficient solutions. It's not a case of reports and your second approach assumes the user logs in.

My case is perhaps simpler than you expected: Every week the script must check whether a user has been active in the game (completed certain tasks or has been 100% inactive) and then send mail to the user to remind him to play. If the player signed up and never logged in, he still needs to get a reminder mail.

It's not a problem that Playfab does not support cron job like feature, since I will then use my own server to create a cron job that queries the Platfabs API and check the user's activity.

Again, thanks for all the information.


Brendan Vanous said on Fri, 13 February 2015 at 12:21 PM

Ah, I see. In that case, I'll add that Premium tier titles have access to our advanced analytics, which includes the ability to define segments of users (such as "hasn't logged in within the last 7 days") to whom you can send Push Notifications via the Game Manager. We'll be adding more ways you can use the segments defined shortly, but right now can export the data for users in a segment via the analytics (Appuri) page, which you could then use for email outreach.

I will add that I would recommend having a clear opt-in for emails as part of the user sign-up process, so that you can limit these mails to people who have given you permission to do this. Bear in mind that mails like this could be considered promotion of your game, in which case you could run afoul of legislation such as the CAN_SPAM Act, the EU Directive on Privacy and Electronic Communications (Article 13 - "Unsolicited communications"), and Canada's Anti-Spam Legislation.


krellumdead said on Mon, 15 June 2015 at 12:34 PM

Yes I am very interested in this topic. I am well away that cron jobs are a non-starter if you want scale. If you launch a cron job for each player and you have a million players you have just killed server memory while trying to load that many cron tasks into the scheduler.

In general time can be handled with what I call the Schrödinger's Cat Algorithm: don't care or know if a time has passed until you need to know, then check. This covers about 95% of timing needs. Need to display VC? Yes check the clock and see how much you should have created by now and create it before displaying it. Need to know if a skill has been regenerated? Just before you display the icon check the time and see if enough time has passed and set icon state accordingly. It is easy to think we need to know if the time has expired when it does; 99 times out of a hundred it is a lie! All you need to do is record a time stamp and duration at the start of a time period than compare to the current time why you really need to know.

The one case this does not work for is non-administrative timeout warnings. Admin stuff you can just use analytics once a day to see if you need to send emails or other such admin stuff. This can be a cron job on the admin system, no scale issues.

But! If you have say a spell that lasts 3 hours and you want to give a push notification 15 minuets before it runs out that is harder! This is not something you put off knowing until you need to know. It is something must happen when it happens - within reasonable granularity. In typical UI systems you have a command loop, or animation refresh loop, or physics loop where any registered object with an "update" method of some sort is called. In that loop you can use the Schrödinger's Cat Algorithm it get times to the resolution of the update loop.

I would like to see PlayFab add a dynamics loop of some sort. Ideally that we could set the refresh rate. This means one cron job in PlayFab to manage the loop, not one per player or one per object or .... And it means a list of data objects that are just CloudScript references to "update functions and time stamps of when the function should be called. If the list got too long and the update rate was too short you would never get to the end of the list but that could be reported by the analytic system.


Brendan Vanous said on Mon, 15 June 2015 at 7:22 PM

I've moved this over to the Feature Requests forum, for clarity.

You are quite correct that a cron job which operates across all users would be a bad idea, for exactly the reasons you state. Not to mention the fact that the action could not be simultaneous across all users (because, physics), making an adjustment to players which should be equal between players entering a session together impossible using that method (which is why we recommend actions on sign-in).

I'll add a request for an action on a user which has a timer to our backlog - thanks for the suggestion!

Brendan


gtgamestudio said on Thu, 09 July 2015 at 12:55 PM

We were looking for a similar feature to the original poster's question: we have a daily maintenance process that needs to run regardless of player activity, but currently the only way for us to do this is by having a developer initiate the process manually or set up a 3rd party server that does support cron jobs.

If possible, we'd like to keep all of our server infrastructure on one platform (this is why we initially chose PlayFab), so we would like to avoid having to go elsewhere for a single simple task.


Brendan Vanous said on Thu, 09 July 2015 at 1:32 PM

Could you provide some details on the maintenance process specifics? If it's gathering data on players, that can be done using our analytics and reporting systems. If it's modification to players, that's usually best done as an active update, when the player signs in or when another player takes action upon them. But depending on what it is you're trying to accomplish, there may be other recommendations.


gtgamestudio said on Thu, 23 July 2015 at 10:18 AM

The process would be modifying groups of players, and needs to happen even if no players are currently signed in or taking actions. What other recommendations do you have?


Brendan Vanous said on Thu, 23 July 2015 at 11:54 PM

So again, that's more a description of the solution you have in mind, rather than the actual problem you're attempting to solve. If you could let us know why you need to update all these players as a group, rather than updating them when they sign in, and provide some context on the gameplay involved, that would help us to design an appropriate solution to this issue.


gtgamestudio said on Fri, 24 July 2015 at 6:52 AM

The players are divided into pods, and each day their productivity within the game is measured against the others in their pod. Every day at 5pm, the most productive members are promoted, the least are demoted, and the pods are reassigned.


krellumdrac said on Fri, 24 July 2015 at 8:30 AM

It seems to me that your behavior should be completely managed without any need for cron-like jobs. As "productivity" events happen you update the players productivity measurements all the time. Each time you need to know what pod they are in you check the date/time. If it is pre-5pm you use the old pod. If it is post 5 you use the on going productivity measurement to assign a new pod and register the date/time when the data was updated. It really comes back to Schrödinger's Cat you don't need to know or to care until you need to know and care. So check the date/time when you need to look up pod membership and adjust according at that time. If the members of the pod was not actually figured out until 7PM because that was the first time a player' pod was checked does that matter? As long is it is figured out when it first needs to be known who cares if it was really at 7PM? As long as the process treats it like it happened at 5 PM it all be handled with stepwise tracking.


krellumdrac said on Fri, 24 July 2015 at 8:33 AM

Note too my company (dessec.com) consults on these type of game algorithm issues. If you want to spend a little I will gladly write up the details.

10 |1200

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

brendan avatar image
brendan commented

Please have a look at the Scheduled Tasks feature, in the Automation tab of the Game Manager - you can set up regularly scheduled calls to Cloud Script handlers for your game at the title level, or on player segments.

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 a Comment

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

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.

Related Ideas