Sha256: 0a4e39fe78ce114eceee2176aa35867190645af3f2459818f185d5fe45d19e20

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

# Extend Resque::Server to add tabs
module ResqueScheduler
  
  module Server

    def self.included(base)

      base.class_eval do

        helpers do
          def format_time(t)
            t.strftime("%Y-%m-%d %H:%M:%S %z")
          end

          def queue_from_class_name(class_name)
            Resque.queue_from_class(Resque.constantize(class_name))
          end
        end

        get "/schedule" do
          Resque.reload_schedule! if Resque::Scheduler.dynamic
          # Is there a better way to specify alternate template locations with sinatra?
          erb File.read(File.join(File.dirname(__FILE__), 'server/views/scheduler.erb'))
        end

        post "/schedule/requeue" do
          config = Resque.schedule[params['job_name']]
          Resque::Scheduler.enqueue_from_config(config)
          redirect u("/overview")
        end
        
        get "/delayed" do
          # Is there a better way to specify alternate template locations with sinatra?
          erb File.read(File.join(File.dirname(__FILE__), 'server/views/delayed.erb'))
        end

        get "/delayed/:timestamp" do
          # Is there a better way to specify alternate template locations with sinatra?
          erb File.read(File.join(File.dirname(__FILE__), 'server/views/delayed_timestamp.erb'))
        end
        
        post "/delayed/queue_now" do
          timestamp = params['timestamp']
          Resque::Scheduler.enqueue_delayed_items_for_timestamp(timestamp.to_i) if timestamp.to_i > 0
          redirect u("/overview")
        end

      end

    end

    Resque::Server.tabs << 'Schedule'
    Resque::Server.tabs << 'Delayed'

  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
resque-scheduler-2.0.0.d lib/resque_scheduler/server.rb