-
Notifications
You must be signed in to change notification settings - Fork 1
/
manager.rb
117 lines (98 loc) · 2.24 KB
/
manager.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require 'rubygems'
require 'sinatra'
require 'haml'
require 'active_record'
require 'sinatra/static_assets'
require 'less'
require "sinatra/reloader"
use Rack::Lint
configure do
LOGGER = Logger.new("sinatra.log")
end
helpers do
def logger
LOGGER
end
end
set :public, File.dirname(__FILE__) + '/static'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:dbfile => 'gearman.sqlite3.db'
)
#Models
class Job < ActiveRecord::Base
self.table_name = "gearman_queue"
set_primary_key :unique_key
named_scope :unique_functions, :select => "function_name, COUNT(*) AS count", :group => "function_name"
end
# Methods
get '/' do
@jobs = Job.all
haml :index
end
get '/css/stylesheet.css' do
content_type 'text/css', :charset => 'utf-8'
less :stylesheet
end
#Jobs
get '/jobs' do
@job_types = Job.unique_functions
haml :'jobs/index'
end
get '/jobs/new' do
@job = Job.new
haml :'jobs/new'
end
post '/jobs' do
@job = Job.new(params[:post])
if @job.save
redirect "/jobs/#{@job.id}"
else
"There was a problem saving that..."
end
end
post '/jobs/update/:id' do
@job = Job.find(params[:id])
logger.debug params.inspect
@job.update_attributes(params[:job])
redirect "/jobs/show/#{@job.unique_key}"
end
get '/jobs/:function_name' do
@function_name = params[:function_name]
@jobs = Job.find(:all, :conditions => ['function_name = ?', params[:function_name]], :order => 'when_to_run DESC')
haml :'jobs/list'
end
get '/jobs/show/:id' do
@job = Job.find(params[:id])
@jobtimestr = Time.at(@job.when_to_run).strftime('%B %d, %Y @ %H:%M:%S %p')
@priorities = {
0 => 'High',
1 => 'Normal',
2 => 'Low',
}
haml :'jobs/show'
end
get '/jobs/edit/:id' do
@job = Job.find(params[:id])
@jobtimestr = Time.at(@job.when_to_run).strftime('%B %d, %Y @ %H:%M:%S %p')
@priorities = {
0 => 'High',
1 => 'Normal',
2 => 'Low',
}
haml :'jobs/edit'
end
__END__
@@ layout
%html
%head
%title Gearman Job Queue
%meta{"http-equiv"=>"Content-Type",
:content=>"text/html; charset=utf-8"}/
= stylesheet_link_tag '/css/stylesheet.css'
%h1 Gearman manager
%div{:id => "menu"}
%ul
%li
%a{:title => "Job Queues", :href => "/jobs"} Job Queues
= yield