Rewrote the scheduler in an agent-centric way

This seems to perform better than the old one.
Start scheduler on agent only if one is assigned

Shouldn't be a big deal in practice, because tasks with no agent
assigned will not reach "DONE" or "FAILED" states, it did break
a unit test, though.
Use locking in assign_tasks_to_agent

We were experiencing some parallelism problems where two or more
instances of assign_tasks_to_agent were running at the same time for the
same agent and ended up assigning more tasks than they should for that
agent.

In theory, database transactions should take care of that, but somehow
they don't.  Weird.
Write time to lockfile
Set job state to running when starting it
Avoid division by zero
Don't use relationship to get child queues

The top queue is not actually a database object, and as such, its
relationship attributes won't work as expected
Actually call method
Don't count NULL as an assigned agent id
Honor job dependencies
Catch OSError
Don't use reserved word "file" for variable
Add a few newlines for improved readability
Make logging at level debug configurable
Add optional link to a URL for a job's output
Adopt test to new column Job.output_link
Rename loop variable i->object
Filter out current task when counting active tasks

We are sometimes experiencing problems with jobs not getting set to
failed or done after their last task stops running.  This is an attempt
to address that problem.
Merge pull request #283 from guidow/job_end_changes

Filter out current task when counting active tasks
Merge pull request #278 from guidow/agent_centric_scheduler

Rewrite the scheduler in an agent-centric way