Permalink
Browse files

Initial status page started

  • Loading branch information...
1 parent 217279b commit 81be2777eaa377e3d80f531c353d83f90214b83a Justin Knowlden committed Dec 19, 2008
View
@@ -62,7 +62,10 @@ delayed_job
## Requirements
* [Sinatra](http://github.com/bmizerany/sinatra/tree/master)
+* [Chicago](http://github.com/thumblemonks/chicago/tree/master)
* Ruby JSON
+* [Delayed Job - Thumble Monks remix](http://github.com/thumblemonks/delayed_job/tree/master)
+* Rest Client
## Setting up an app
@@ -76,6 +79,8 @@ We're still working this out.
### Configuration
TBD
+
+ Includes some stuff for running a God task
### Running
View
@@ -9,7 +9,7 @@ def require_local_lib(path)
require 'sinatra'
require 'chicago'
-set :run, false
+set(:run, false) unless ENV['APP_ENV'] == 'development'
require_local_lib('../lib')
require_local_lib('../models')
View
@@ -41,8 +41,6 @@ def manage_resource(resource)
manage_resource(Callback.new(params)) do |callback|
callback.save!
CallbackRunner.make_job_from_callback!(callback)
- # job = Delayed::Job.enqueue(callback, 0, callback.callback_at)
- # callback.update_attributes!(:delayed_job => job)
end
end
@@ -51,8 +49,32 @@ def manage_resource(resource)
attributes = params.reject {|k,v| k == "guid"}
callback.update_attributes!(attributes)
CallbackRunner.replace_job_for_callback!(callback)
- # callback.delayed_job.destroy if callback.delayed_job
- # job = Delayed::Job.enqueue(callback, 0, callback.callback_at)
- # callback.update_attributes!(:delayed_job => job)
end
end
+
+# Status and stuff
+
+template(:layout) {:application}
+
+catch_all_css
+
+helpers do
+ def truncate(str, n)
+ str.length > n ? "#{str[0..n]}..." : str
+ end
+
+ def verbal_status_message(callback)
+ if callback.called_back?
+ haml '.okay Already evoked callback', :layout => false
+ elsif callback.should_have_been_called_back? && !callback.called_back?
+ haml '.uhoh This callback should have been evoked but has not yet', :layout => false
+ else
+ haml '.okay Just waiting for callback time', :layout => false
+ end
+ end
+end
+
+get "/status" do
+ @callbacks = Callback.recent
+ haml :status
+end
View
@@ -7,10 +7,16 @@ class Callback < ActiveRecord::Base
before_save :data_cannot_be_nil
before_save :guid_cannot_be_blank
+ named_scope :recent, :order => 'created_at desc', :limit => 10
+
def self.by_guid(guid)
first(:conditions => {:guid => guid})
end
+ def should_have_been_called_back?
+ callback_at < Time.now
+ end
+
private
def data_cannot_be_nil
write_attribute(:data, '') if data.nil?
@@ -3,7 +3,7 @@ class CallbackRunner
def self.make_job_from_callback!(callback)
runner = CallbackRunner.new(callback)
job = Delayed::Job.enqueue(runner, 0, callback.callback_at)
- callback.update_attributes!(:delayed_job => job)
+ callback.update_attributes!(:delayed_job => job, :called_back => false)
end
def self.replace_job_for_callback!(callback)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
@@ -26,14 +26,14 @@ def callback_with_runner(attributes={})
should "update callback with the new job" do
job = stub('job')
Delayed::Job.expects(:enqueue).returns(job)
- @callback.expects(:update_attributes!).with({:delayed_job => job})
+ @callback.expects(:update_attributes!).with({:delayed_job => job, :called_back => false})
CallbackRunner.make_job_from_callback!(@callback)
end
end
context "replacing job for callback" do
setup do
- @callback = Factory(:callback)
+ @callback = Factory(:callback, :called_back => true)
end
context "when callback has a job" do
@@ -58,8 +58,14 @@ def callback_with_runner(attributes={})
CallbackRunner.expects(:new).with(@callback).returns(@runner)
job = stub('job')
Delayed::Job.expects(:enqueue).with(@runner, 0, @callback.callback_at).returns(job)
- @callback.expects(:update_attributes!).with({:delayed_job => job})
+ @callback.expects(:update_attributes!).with({:delayed_job => job, :called_back => false})
+ CallbackRunner.replace_job_for_callback!(@callback)
+ end
+
+ should "set called back to false" do
CallbackRunner.replace_job_for_callback!(@callback)
+ @callback.reload
+ deny @callback.called_back?
end
end
View
@@ -39,4 +39,16 @@ class CallbackTest < Test::Unit::TestCase
end
end
+ context "should have been called back" do
+ should "return true if callback at is in the past" do
+ @callback = Factory(:callback, :callback_at => Time.now - 1.day)
+ assert @callback.should_have_been_called_back?
+ end
+
+ should "return false if callback at is in the future" do
+ @callback = Factory(:callback, :callback_at => Time.now + 1.day)
+ deny @callback.should_have_been_called_back?
+ end
+ end
+
end
@@ -2,8 +2,30 @@
!!!
%html
%head
+ %meta{"http-equiv" => 'X-UA-Compatible', :content => 'GROW UP'}
+ %meta{:name => 'viewport', :content => 'width=850'}
%title
- Thumblemonks
- = @title
+ Evoke - Status
+ %link{:href => "/images/tm-block.gif", :rel => "icon"}
+ = stylesheet_include 'reset-min'
+ = stylesheet_include 'application'
%body
- = yield
+ #header
+ .container
+ %a.logo{:href => "http://thumblemonks.com"}
+ %img{:src => "/images/header-logo.gif"}
+ %ul.nav
+ %li{:class => 'current'}
+ %a{:href => '/evoke'} Evoke
+ .clear
+
+ #content
+ = yield
+ .clear
+
+ #footer
+ .container
+ %a{:href => "http://creativecommons.org/licenses/by-nc-nd/3.0/"} Copyright &copy;
+ 2007 -
+ = Time.now.year
+ %a{:href => "http://thumblemonks.com/"} Thumble Monks
View
@@ -0,0 +1,114 @@
+body
+ :width 100%
+ :text-align center
+ :margin .5ex 0ex
+ :padding 0em
+ :background-color white
+ :font normal 11pt times, serif
+
+.clear
+ :clear both
+
+a, a:visited
+ :color #845381
+
+.container
+ :width 850px
+ :margin 0 auto
+ :text-align left
+ :padding 0
+
+#header
+ :background-color #231f20
+ a.logo
+ :float left
+ :padding 1ex 0 .5ex 0
+ :margin 0 2em 0 0
+ ul.nav
+ :display block
+ li
+ :float left
+ :padding 1ex 1ex 1ex 1ex
+ :margin 1.15em 1ex 0 1ex
+ a
+ :color #ddd
+ :text-decoration none
+ :text-transform uppercase
+ :letter-spacing 1px
+ :font normal 8pt "Lucida Sans Unicode", Arial, sans-serif
+ &.current
+ :background-color #fff9d8
+ a
+ :color #a483a1
+#footer
+ :margin 2em 0 0 0
+ :color #ddd
+ :font normal 9pt "Lucida Sans Unicode", Arial, sans-serif
+ :background-color #231f20
+ a, a:visited
+ :color #a483a1
+ .container
+ :padding 2em 0 1ex 0
+
+#content
+ :margin 0 0 1em 0
+ #title
+ :background-color #fff9d8
+ :border-bottom 1px solid #ffe8cd
+ :margin 0 0 1em 0
+
+ h1
+ :font normal 24pt Georgia, times, serif
+ :margin 0 0 0 0
+ :padding 1ex 0 .5ex 0
+ :color #433f40
+
+ h2
+ :font normal 16pt Georgia, times, serif
+ :margin 1em 0
+ :color #231f20
+ :padding 0 0 .5ex 0
+ :border-bottom 1px dotted #ccc
+
+ h3
+ :font normal 13pt "Lucida Sans Unicode", Arial, sans-serif
+ :margin 1em 0
+ :letter-spacing -1px
+ :color #444
+
+ h4
+ :font bold 11pt Arial, sans-serif
+ :margin 1ex 0
+ :color #555
+
+ #columns
+ .left
+ :float left
+ :width 50%
+ .sidebar
+ :float right
+ :width 40%
+
+ .running
+ :color green
+
+ li.callback
+ :border-bottom 1px solid #ccc
+ :padding 1ex 0
+
+ .info
+ :font normal 10pt Arial, sans-serif
+ :padding 0 0 .5ex 0
+ span
+ :padding 0 1em 0 0
+ .label
+ :color #888
+ :font-weight bold
+ .data
+ :color #222
+ .okay
+ :color green
+ :padding 0 0 1ex 0
+ .uhoh
+ :color red
+ :padding 0 0 1ex 0
View
@@ -0,0 +1,35 @@
+#title
+ .container
+ %h1.running Running
+
+.container
+ #columns
+ .left
+ %h3 Last 10 Callbacks
+ %ul
+ - @callbacks.each do |callback|
+ %li.callback
+ .info
+ = verbal_status_message(callback)
+ .info
+ %span.label Callback
+ %span.data
+ = callback.method.upcase
+ = truncate(callback.url, 50)
+ .info
+ %span.label Evoke on
+ %span.data= callback.callback_at.strftime("%b %d %H:%M:%S")
+ .info
+ %span.label Created on
+ %span.data= callback.created_at.strftime("%b %d %H:%M:%S")
+ - if callback.guid
+ .info
+ %span.label GUID
+ %span.data= callback.guid
+ - if callback.error_message
+ .info
+ %span.label Errors
+ .data= callback.error_message
+ .sidebar
+ %h3 Stats
+ Something

0 comments on commit 81be277

Please sign in to comment.