Ensure logs from worker background thread are delivered.

Due to thread-safety issues in ActiveSupport::BufferedLogger
we make sure that log messages are flushed after each worker cycle and
at the (unexpected) end of worker thread.

Related issues:
https://github.com/rails/rails/pull/3394
http://stackoverflow.com/questions/1598494/logging-inside-threads-in-a-rails-application