Django task queue

I've only heard of tools like Celery, but I don't know if it suits my needs and is the best solution I can have.

Imagine a game like Travian. We are starting construction and we need to wait N seconds for the construction to be completed. When and how should we complete construction?


Solution 1: Check if there is an active construct every time the page is loaded. If such requests take some time, we can make them asynchronous. If they are, then complete.

However, this way we constantly wait for the user to reload the page. Of course, we can use a cronjob to check from time to time, but the cronjobs are executed once a minute or less. Constructs / attacks, etc. Should be performed as accurately as possible.


The solution above works, but has some downsides. What are the best and RELIABLE ways to perform actions like the ones I mentioned.

Also, suppose resources need to be regenerated at a rate X per hour

, and we need to regenerate them very accurately and quite often. How can I achieve this without waiting for the page to refresh?


Finally, the solution should work on the Webfaction host or any other shared hosting. I heard that celery doesn't work in Webfaction, or am I wrong?

+3


source to share


1 answer


Yes, celery has periodic jobs with seconds: http://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html Also you can start jobs in time with celeryab celery http://celery.readthedocs.org/ en / latest / userguide / periodic-tasks.html # crontab-schedules

Also, if you need to check the amount of resources, I think this is a common part for each request, so your response should look like

{
   "header": {"resources": {"wood":1, "stone":500}}
   "data": {.. you real data shoud be here...}
}

      



You need to add a header for the response, which will contain general information such as resource counts, unread messages, etc. and handle them correctly on the client.

To improve it, you can use nginx + ssl + memcache server.

0


source







All Articles