Update job state after task not found on agent

This used to be done as part of an event handler triggered whenever the
task's state was updated, but it no longer is, because of a race
condition, so now we need to do it manually.
Lock job before assigning an agent to it.

This avoids a problem where the same batch of tasks is sent to more than
one agent to process.
Reduce frequency for polling offline agents

In a big farm, offline agents are bound to be a common occurence.
Polling them, however, can take until a timeout is reached, 10 seconds
by default. Polling offline agents too often can possibly clog up the
celery task queue.
Adapt tests to new column last_polled
Merge pull request #319 from guidow/missing_tasks_fixes

Update job state after task not found on agent
Merge pull request #320 from guidow/per_job_locks

Lock job before assigning an agent to it.
Merge pull request #321 from guidow/agent_poll_reduction

Reduce frequency for polling offline agents