Permalink
Browse files

Feature to cleanup old todo items, backed by chronatog. Not actually …

…working
  • Loading branch information...
1 parent 29a2017 commit c61057abeeb465d49e7c137841a6ff3c61175d9e @jacobo jacobo committed Nov 8, 2011
View
@@ -5,6 +5,10 @@ gem 'rails', '3.0.9'
gem 'simple_form', '1.5.1'
gem 'jquery-rails', '1.0.14'
+gem 'ey_config'
+gem 'json'
+gem 'chronatog-client', :require => 'chronatog/client'
+
platform :ruby do
gem 'mysql2', '~> 0.2.7'
gem 'pg'
View
@@ -32,8 +32,11 @@ GEM
arel (2.0.10)
bouncy-castle-java (1.5.0146.1)
builder (2.1.2)
+ chronatog-client (0.2.0)
+ rack-client
erubis (2.6.6)
abstract (>= 1.0.0)
+ ey_config (0.0.1)
i18n (0.5.0)
jdbc-mysql (5.1.13)
jdbc-sqlite3 (3.7.2)
@@ -43,6 +46,8 @@ GEM
jruby-openssl (0.7.4)
bouncy-castle-java
jruby-rack (1.0.10)
+ json (1.6.1)
+ json (1.6.1-java)
kgio (2.6.0)
mail (2.2.19)
activesupport (>= 2.3.6)
@@ -54,6 +59,8 @@ GEM
pg (0.11.0)
polyglot (0.3.2)
rack (1.2.4)
+ rack-client (0.4.0)
+ rack (>= 1.0.0)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
@@ -99,10 +106,13 @@ PLATFORMS
DEPENDENCIES
activerecord-jdbc-adapter
+ chronatog-client
+ ey_config
jdbc-mysql
jdbc-sqlite3
jquery-rails (= 1.0.14)
jruby-openssl
+ json
mysql2 (~> 0.2.7)
pg
rails (= 3.0.9)
@@ -0,0 +1,25 @@
+class CleanupController < ApplicationController
+
+ def index
+ @setup = (cron_client.list_jobs.size > 0)
+ end
+
+ def setup
+ cron_client.create_job(run_cleanup_url, "* */1 * * *") #callback every hour
+ redirect_to cleanup_url
+ end
+
+ def run
+ #Doesn't actually do anything :-P
+ render :text => "ok"
+ end
+
+private
+
+ def cron_client
+ @client ||= Chronatog::Client.setup!(EY::Config.get(:chronatog, 'service_url'),
+ EY::Config.get(:chronatog, 'auth_username'),
+ EY::Config.get(:chronatog, 'auth_password'))
+ end
+
+end
@@ -0,0 +1,2 @@
+module CleanupHelper
+end
@@ -0,0 +1,11 @@
+<p>Getting things done is great.</p>
+
+<p>But when they don't get done, they just sit there on your list and make you feel icky.</p>
+
+<p>So let's just expire old items!</p>
+
+<% if @setup %>
+ <p>Item expiration cron is setup!</p>
+<% else %>
+ <p>Item expiration cron is not setup: <%=link_to "Setup now!", setup_cleanup_url %></p>
+<% end %>
@@ -0,0 +1,5 @@
+---
+chronatog:
+ auth_username: foo
+ auth_password: bar
+ service_url: "in-memory"
View
@@ -4,6 +4,10 @@
resources :tasks, :except => [:new, :edit, :show]
end
+ match 'cleanup' => 'cleanup#index', :as => :cleanup
+ match 'cleanup/run' => 'cleanup#run', :as => :run_cleanup
+ match 'cleanup/setup' => 'cleanup#setup', :as => :setup_cleanup
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -0,0 +1,26 @@
+require 'test_helper'
+
+class CleanupControllerTest < ActionController::TestCase
+ setup do
+ @list = lists(:one)
+ @task = tasks(:one)
+ end
+
+ test "get index works" do
+ get :index
+ assert_response :success
+ end
+
+ test "setting up" do
+ get :setup
+ assert_response :redirect
+ get :index
+ assert_response :success
+ end
+
+ test "running" do
+ post :run
+ assert_response :success
+ end
+
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class CleanupHelperTest < ActionView::TestCase
+end

0 comments on commit c61057a

Please sign in to comment.