Sha256: a68c3f21c135fff8198613a0bd242de3b22f495868ac896c5904f7d348a6aa76

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 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")
          end

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

        get "/schedule" do
          # 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 url("/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.present?
          redirect url("/overview")
        end

      end

    end

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

  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
resque-scheduler-1.9.3 lib/resque_scheduler/server.rb
resque-scheduler-1.9.2 lib/resque_scheduler/server.rb
resque-scheduler-1.9.1 lib/resque_scheduler/server.rb
resque-scheduler-1.8.2 lib/resque_scheduler/server.rb