Job Queue

0 favourites
  • 4 posts
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

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

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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)