Make sure test is actually doing something.

The test wasn't calling Edition.publish_all_due_editions_as, so the
code we are supposed to be testing wasn't actually getting excercised.
Extract scheduled publishing to a worker class

The work of publishing a scheduled edition has been pulled out to a
separate class that intentionally mirrors the API used by background
job systems like sidekiq and resque. This is so that if/when we move
to a proper job queue system for handling scheduled publishings, we
can simply queue one of these workers at the point the edition is
scheduled to be published and leave the job system to handle the
scheduling of the job and retries in the event of failure.
Remove cruft

It doesn't matter what publish_atomically_as returns; creating
the robot if it doesn't exist shouldn't happen in the model;
acting_as method is no longer used; Logging due count in statsd is not
useful.
Fix scheduling robot factory
Extract scheduled publishing out to its own class

This now tests the waiting until publish time, although that involves
a second-long pause in the tests. If anyone can think of a better way
to test this, I'd love some feedback.
Add retry code for scheduled edition publishing

We retry up to 5 times before giving up by raising an exception. The
plan is to catch this exception and report it using the exception
notification system in the next commit.
Extract waiting logic out to Whitehall grab bag

On @h-lame's excellent suggestion, I've pulled out the logic for
waiting until a given time to it's own method outside of the
scheduling code.
Update to latest exception notification gem

This is so I can make use of the background_exception_notification
method during rake tasks. This should be a drop-in replacement.
Catch & report scheduled publishing failures

In theory, this should not happen very often, if at all, as we'd
expect after 5 attempts, all scheduled editions to be successfully
published, even with contention between backend servers. When this
does happen though, we use exception notifier to report the failure,
including log output of what happened and the ids of the editons that
failed to be published.
DRY up "acting as" code

Pulled out the common logic for switching between users to the
Edition::AuditTrail module. Note that the use of a class-level
attr_accessor in AuditTrail is not thread-safe. Using Thread.current
would be a better solution, especially if we ever intend to use
something like sidekiq for processing background jobs.
Improve logging
Clarify automatic isolation level revertion

See https://github.com/alphagov/whitehall/commit/9a41dcdb5fc01546dd267a88385b2c1f5a12b1d8#commitcomment-2900045
for more details.
Merge pull request #402 from alphagov/fix-scheduled-publishing

Make scheduled publishing more robust

https://www.pivotaltracker.com/story/show/46889987