Refactor assign_tasks to use get_batch_agent_pair

assign_batch_at_prio() has now been renamed to get_batch_agent_pair(),
and instead of directly assigning tasks to an agent at a priority level,
it will return a tuple of a list of tasks and agent they can be assigned
to, leaving the actual assigning to the caller.

This is necessary because assign_tasks will need to queue a
send_tasks_to_agent() task for every agent that has been assigned new
tasks, but it must do that after committing its database transaction. In
the previous architecture, assign_tasks() never actually which agents
exactly where touched.
Bugfix: waiting WorkStates can be NULL
Bugfix: IP addresses to string for HTTPConnection
Use default_json_encoder when encoding message

Otherwise, some custom types like Decimal or datetime cannot be encoded
Bugfix: Logger has no "notice" method
Add some more logging
Queue send tasks_to_agent after assigning tasks