Job Queue

Discuss game development design and post your game ideas

Post » Fri Jan 25, 2013 11:50 pm

I need a server side job queue solution.

Say a player sends an attack against an opposing player's city. That attack takes one hour to arrive. I want my app to resolve the combat after the hour has elapsed, even if the player is logged off or his session has expired.

I need better resolution than something like a cron job can provide.

Any suggestions?
B
30
S
5
G
4
Posts: 26
Reputation: 5,247

Post » Wed Jan 30, 2013 10:46 am

It really depends on what resolution of repeat interval you require, and what platform your server is running, but here's some thoughts:

I believe the shortest repeat interval for UNIX Cron tasks and Windows Task Scheduler tasks is every 1 minute. Given that you're talking about actions that last one hour, is this not sufficient resolution?

If you need something more frequent then you could create some sort of daemon or service running on the server that constantly polls the current time in a loop and calls the corresponding actions as necessary. Be careful though - badly written daemons are an easy way to kill a server (and you'll need to own the server on which it's running - shared hosts generally don't let you run ongoing processes). The way to write the daemon would obviously depend on the server OS.

My only other thought is that I'm assuming you're using a database to manage the job queue, in which case, you should check whether the database has inbuilt scheduling functionality. For example, SQL Server has an agent that lets you call a stored procedure on a schedule that can be repeated every second (if you *really* want to run it every second). That procedure can check the queue table, and process jobs accordingly. I don't know, but I guess that other databases come with equivalent scheduling functionality.
B
8
S
2
G
3
Posts: 83
Reputation: 2,668

Post » Wed Jan 30, 2013 7:07 pm

If this A-Sync/Realtime then you will want to use websockets/node.js or your never going to pass data quick enough between players.

If its turn based or you dont need to refresh the data too much you're probs best storing the data in a database and then using Ajax/PHP or something to fetch it saving it all locally to an array and playing out everything from that instead.
B
14
S
3
G
5
Posts: 41
Reputation: 3,490

Post » Thu Jan 31, 2013 2:28 am

Thanks guys, for your time.

As far as resolution goes, I need it to be as fine as possible. What if player A's attack lands on player B's camp at nearly the same time as player C's attack? I want the first attacker to take the loot, so I need to update the defender's records before the second attack is resolved.

I think I agree that a websockets/node.js solution is called for. However I am running a Zend PHP server which has some job queue functionality, so stay tuned.

Thanks again.
B
30
S
5
G
4
Posts: 26
Reputation: 5,247


Return to Game Development, Design & Ideas

Who is online

Users browsing this forum: amariscal and 0 guests