Skip to content
Browse files

added manage schedules

  • Loading branch information...
1 parent 55c5b7a commit 6c901f0406c128251c387f70777fc859513fdb0b @rkononov rkononov committed Sep 6, 2012
View
12 app/controllers/schedules_controller.rb
@@ -1,4 +1,16 @@
class SchedulesController < ApplicationController
def index
+ @schedules = client.schedules.list
+ end
+
+ def cancel_schedule
+ client.schedules.cancel(params[:id])
+ redirect_to schedules_path
+ end
+
+ def schedule_task
+ res = client.schedules.create(params[:worker_name], JSON.parse(params[:schedule_params]), {:start_at => Time.now + params[:seconds].to_i })
+ puts "Result:#{res.inspect}"
+ redirect_to schedules_path
end
end
View
2 app/views/codes/index.html.erb
@@ -9,6 +9,7 @@
<td>Revision</td>
<td>Actions</td>
<td>Queue!</td>
+ <td>Schedule!</td>
</tr>
</thead>
@@ -23,6 +24,7 @@
<%= link_to "Download", download_code_path(c.id) %>
</td>
<td><%= button_to "Queue!", queue_tasks_path(:worker_name => c.name) %></td>
+ <td><%= button_to "Schedule!", schedule_task_schedules_path(:worker_name => c.name, :seconds => 10) %></td>
</tr>
<% end %>
</table>
View
59 app/views/schedules/index.html.erb
@@ -1,19 +1,42 @@
<h1>Scheduled tasks</h1>
-<p>
-<ul>
- <li>
- 10) schedule task
- schedule = client.schedules.create('MyWorker', {:client => 'Joe'}, {:start_at => Time.now + 3600})
- <li>
- 11) list of scheduled task
- client.schedules.list.each do |schedule|
- puts schedule.inspect
- end
- puts client.schedules.get('1234567890').last_run_time
- </li>
- <li>
- 10) cancel scheduled task
- client.schedules.cancel('1234567890')
- </li>
-</ul>
-</p>
+
+<h3>List of scheduled tasks:</h3>
+<% if !@schedules.empty? %>
+ <table border="1">
+ <thead>
+ <tr>
+ <td>Code Name</td>
+ <td>Created at</td>
+ <td>Status</td>
+ <td>Start at</td>
+ <td>Next start</td>
+ <td>Actions</td>
+ </tr>
+ </thead>
+
+ <% @schedules.each do |t| %>
+ <tr>
+ <td><%= t.code_name %></td>
+ <td><%= t.created_at %></td>
+ <td><%= t.status %></td>
+ <td><%= t.start_at %></td>
+ <td><%= t.next_start %></td>
+ <td>
+ <%= button_to "Cancel", cancel_schedule_path(t.id) %>
+ </tr>
+ <% end %>
+ </table>
+<% else %>
+ <h5>There are now any active scheduled tasks, feel free to schedule new one</h5>
+<% end %>
+
+<%= form_tag(schedule_task_schedules_path) do %>
+ <%= label_tag(:worker_name) %>
+ <%= text_field_tag(:worker_name, "HelloWorker") %>
+ <%= label_tag(:schedule_params) %>
+ <%= text_field_tag(:schedule_params, '{"text":"sample"}') %>
+ <%= label_tag(:seconds) %>
+ <%= select_tag "seconds", options_for_select([5, 10, 15], 1) %>
+ <%= submit_tag("Schedule") %>
+<% end %>
+<%= link_to "Back", root_path %>
View
6 app/views/tasks/index.html.erb
@@ -31,11 +31,11 @@
<h5>There are now any tasks, feel free to queue new one</h5>
<% end %>
<p>
- <%= form_tag("/queue") do %>
+ <%= form_tag(queue_tasks_path) do %>
<%= label_tag(:worker_name) %>
- <%= text_field_tag(:worker_name) %>
+ <%= text_field_tag(:worker_name,"HelloWorker") %>
<%= label_tag(:task_params) %>
- <%= text_field_tag(:task_params) %>
+ <%= text_field_tag(:task_params,'{"text":"sample"}') %>
<%= submit_tag("Queue") %>
<% end %>
<%=link_to "Back", root_path%>
View
9 config/routes.rb
@@ -21,7 +21,14 @@
get 'log'
end
end
- resources :schedules
+ resources :schedules do
+ collection do
+ post 'schedule_task'
+ end
+ member do
+ post 'cancel'
+ end
+ end
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
View
2 workers/hello_worker.rb
@@ -1,2 +1,2 @@
puts "Hello Worker!"
-puts "I got '#{params}' parameters"
+puts "I got '#{params.inspect}' parameters"

0 comments on commit 6c901f0

Please sign in to comment.
Something went wrong with that request. Please try again.