Skip to content

Commit

Permalink
Added task_manager plugin for viewing the status of background jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
danlucraft committed Apr 17, 2010
1 parent e313b55 commit 785a9f3
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 48 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -16,6 +16,8 @@ New features:
* Project view sorts directories before files (by popular request!)
* Shows menu bar on OSX when there are no windows open
* Halve startup time from 0.3.4 (warm startup)
* Added background Task APIs.
* Task Manager

Fixes:

Expand Down
30 changes: 29 additions & 1 deletion plugins/html_view/assets/redcar.css
Expand Up @@ -9,4 +9,32 @@ td.plugin {

td.links {
text-align: right;
}
}

body {
font-family: sans-serif;
}

h1, h2, h3, h4, h5 {
border-bottom: 1px solid black;
}

table {
border-collapse: collapse;
font-size: 0.8em;
}

th {
padding: 7px 12px;
border: 1px solid #bbb;
}

td {
padding: 7px 12px;
border: 1px solid #bbb;
}

tr.error {
background-color: #FCC;
}

17 changes: 12 additions & 5 deletions plugins/html_view/lib/html_view.rb
Expand Up @@ -20,11 +20,18 @@ def controller=(new_controller)

def controller_action(action_name, path=nil)
action_method_arity = controller.method(action_name).arity
text = if action_method_arity == 0
controller.send(action_name)
elsif action_method_arity == 1
controller.send(action_name, path)
end
begin
text = if action_method_arity == 0
controller.send(action_name)
elsif action_method_arity == 1
controller.send(action_name, path)
end
rescue => e
text = <<-HTML
Sorry, there was an error.<br />
#{e.message}
HTML
end
@html_tab.controller.browser.set_text(text + setup_javascript_listeners)
end

Expand Down
67 changes: 30 additions & 37 deletions plugins/plugin_manager_ui/views/index.html.erb
@@ -1,40 +1,33 @@
<br />
<br />
<div class="container">
<div class="span-8">
<% jquery_path = File.expand_path(File.join(Redcar.root, %w(plugins html_view assets jquery-1.4.min.js))) %>
<script type="text/javascript" src="file://<%= jquery_path %>"></script>
<% blueprint_dir = File.expand_path(File.join(Redcar.root, %w(plugins html_view assets blueprint))) %>
<% redcar_css = File.expand_path(File.join(Redcar.root, %w(plugins html_view assets redcar.css))) %>
<link rel="stylesheet" href="file://<%= blueprint_dir %>/screen.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="file://<%= blueprint_dir %>/print.css" type="text/css" media="print">
<link rel="stylesheet" href="file://<%= redcar_css %>" type="text/css" media="screen">

<h3>Loaded Plugins</h3>
<%= plugin_table(Redcar.plugin_manager.loaded_plugins) %>

<h3>Unloaded Plugins</h3>
<%= plugin_table(Redcar.plugin_manager.unloaded_plugins) %>

<h3>Unreadable definitions</h3>
<%= plugin_table(Redcar.plugin_manager.unreadable_definitions) %>

<h3>Plugins with Errors</h3>
<%= plugin_table(Redcar.plugin_manager.plugins_with_errors) %>

<script language="javascript">
$("a").click(function(e) {
e.preventDefault();
var pluginName = $(this).parent().parent().find(".plugin-name").text();
try {
Controller.reloadPlugin(pluginName);
} catch(e) {
alert(e.message);
}
});
</script>
</div>
</div>
<h3>Plugin Manager</h3>

<% jquery_path = File.expand_path(File.join(Redcar.root, %w(plugins html_view assets jquery-1.4.min.js))) %>
<script type="text/javascript" src="file://<%= jquery_path %>"></script>
<% redcar_css = File.expand_path(File.join(Redcar.root, %w(plugins html_view assets redcar.css))) %>
<link rel="stylesheet" href="file://<%= redcar_css %>" type="text/css" media="screen">

<h4>Loaded Plugins</h4>
<%= plugin_table(Redcar.plugin_manager.loaded_plugins) %>

<h4>Unloaded Plugins</h4>
<%= plugin_table(Redcar.plugin_manager.unloaded_plugins) %>

<h4>Unreadable definitions</h4>
<%= plugin_table(Redcar.plugin_manager.unreadable_definitions) %>

<h4>Plugins with Errors</h4>
<%= plugin_table(Redcar.plugin_manager.plugins_with_errors) %>

<script language="javascript">
$("a").click(function(e) {
e.preventDefault();
var pluginName = $(this).parent().parent().find(".plugin-name").text();
try {
Controller.reloadPlugin(pluginName);
} catch(e) {
alert(e.message);
}
});
</script>


<script type="text/javascript">
Expand Down
7 changes: 2 additions & 5 deletions plugins/project/lib/project.rb
Expand Up @@ -85,13 +85,12 @@ def add_to_recent_files(new_file)
end

def file_list_resource
@resource ||= Resource.new do
puts "refreshing file list for #{self.inspect}"
@resource ||= Resource.new("refresh file list for #{self.inspect}") do
files = []
s = Time.now
files += Dir[File.expand_path(path + "/**/*")]
took = Time.now - s
files = files.reject do |f|
files.reject do |f|
begin
File.directory?(f)
rescue Errno::ENOENT
Expand All @@ -101,8 +100,6 @@ def file_list_resource
true
end
end
puts "done"
files
end
end

Expand Down
1 change: 1 addition & 0 deletions plugins/redcar/redcar.rb
Expand Up @@ -789,6 +789,7 @@ def self.menus
item "Find File", Project::FindFileCommand
end
sub_menu "Debug" do
item "Task Manager", TaskManager::OpenCommand
item "Print Command History", PrintHistoryCommand
item "Print Contents", PrintContents
item "List Tabs", ListTabsCommand
Expand Down
28 changes: 28 additions & 0 deletions plugins/task_manager/lib/task_manager.rb
@@ -0,0 +1,28 @@

require 'erb'
require 'cgi'

module Redcar
class TaskManager
class OpenCommand < Redcar::Command

def execute
controller = Controller.new
tab = win.new_tab(HtmlTab)
tab.html_view.controller = controller
tab.focus
end
end

class Controller
def title
"Tasks"
end

def index
rhtml = ERB.new(File.read(File.join(File.dirname(__FILE__), "..", "views", "index.html.erb")))
rhtml.result(binding)
end
end
end
end
11 changes: 11 additions & 0 deletions plugins/task_manager/plugin.rb
@@ -0,0 +1,11 @@

Plugin.define do
name "task_manager"
version "0.3.5"

object "Redcar::TaskManager"
file "lib", "task_manager"

dependencies "core", ">0",
"HTML View", ">=0.3.2"
end
55 changes: 55 additions & 0 deletions plugins/task_manager/views/index.html.erb
@@ -0,0 +1,55 @@
<% redcar_css = File.expand_path(File.join(Redcar.root, %w(plugins html_view assets redcar.css))) %>
<link rel="stylesheet" href="file://<%= redcar_css %>" type="text/css" media="screen">

<h3>Task Manager</h3>

<a href="controller/index">Refresh</a>

<h4>Pending</h4>

<table>
<tr>
<th>Enqueued</th>
<th>Description</th>
</tr>
<% Redcar.app.task_queue.pending.each do |task| %>
<tr>
<td><%= task.enqueue_time.strftime("%X") %></td>
<td><%= CGI.escapeHTML(task.description || task.class.to_s) %></td>
</tr>
<% end %>
</table>

<h4>In Process</h4>

<table>
<tr>
<th>Started</th>
<th>Description</th>
</tr>
<% if task = Redcar.app.task_queue.in_process %>
<tr>
<td><%= task.start_time.strftime("%X") %></td>
<td><%= CGI.escapeHTML(task.description || task.class.to_s) %></td>
</tr>
<% end %>
</table>

<h4>Completed</h4>

<table>
<tr>
<th>Completed</th>
<th>Description</th>
<th>Duration</th>
</tr>
<% Redcar.app.task_queue.completed.reverse.each do |task| %>
<tr class="<%= "error" if task.error %>">
<td><%= task.completed_time.strftime("%X") %></td>
<td><%= CGI.escapeHTML(task.description || task.class.to_s) %></td>
<td><%= task.completed_time - task.start_time %></td>
</tr>
<% end %>
</table>


0 comments on commit 785a9f3

Please sign in to comment.