# File lib/resque/scheduler.rb, line 35
      def run
        procline 'Starting'

        # trap signals
        register_signal_handlers

        # Quote from the resque/worker.
        # Fix buffering so we can `rake resque:scheduler > scheduler.log` and
        # get output from the child in there.
        $stdout.sync = true
        $stderr.sync = true

        # Load the schedule into rufus
        # If dynamic is set, load that schedule otherwise use normal load
        if dynamic
          reload_schedule!
        else
          load_schedule!
        end

        begin
          @th = Thread.current

          # Now start the scheduling part of the loop.
          loop do
            begin
              if master?
                handle_delayed_items
                update_schedule if dynamic
              end
            rescue Errno::EAGAIN, Errno::ECONNRESET, Redis::CannotConnectError => e
              log! e.message
              release_master_lock
            end
            poll_sleep
          end

        rescue Interrupt
          log 'Exiting'
        end
      end