From 13ab4838e7687abdc453460ed4300e7c7a23316a Mon Sep 17 00:00:00 2001 From: Miroslav Csonka Date: Tue, 24 Mar 2015 22:51:56 +0100 Subject: [PATCH 1/5] Update README.md Fix ruby typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 494498e..8832126 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ Crono comes with a Sinatra application that can display the current state of Cro Add `sinatra` and `haml` to your Gemfile ```ruby -gam 'haml' +gem 'haml' gem 'sinatra', require: nil ``` From 75f1b43c84c6a5ccb087ec7cefb69f72a4ab9ba8 Mon Sep 17 00:00:00 2001 From: Aldric Giacomoni Date: Tue, 24 Mar 2015 17:58:59 -0400 Subject: [PATCH 2/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 494498e..8832126 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ Crono comes with a Sinatra application that can display the current state of Cro Add `sinatra` and `haml` to your Gemfile ```ruby -gam 'haml' +gem 'haml' gem 'sinatra', require: nil ``` From 4b28f3dd80cd81475bd2f2d4e5d2fb83abc1b050 Mon Sep 17 00:00:00 2001 From: Thomas Drake-Brockman Date: Thu, 2 Apr 2015 03:14:08 +0800 Subject: [PATCH 3/5] Updated CLI and Config to default to not writing a pidfile unless daemonized. --- lib/crono/cli.rb | 1 + lib/crono/config.rb | 5 ++++- spec/config_spec.rb | 29 ++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/crono/cli.rb b/lib/crono/cli.rb index d9944a7..a9f18ca 100644 --- a/lib/crono/cli.rb +++ b/lib/crono/cli.rb @@ -50,6 +50,7 @@ module Crono end def write_pid + return unless config.pidfile pidfile = File.expand_path(config.pidfile) File.write(pidfile, ::Process.pid) end diff --git a/lib/crono/config.rb b/lib/crono/config.rb index 5569421..0165477 100644 --- a/lib/crono/config.rb +++ b/lib/crono/config.rb @@ -10,9 +10,12 @@ module Crono def initialize self.cronotab = CRONOTAB self.logfile = LOGFILE - self.pidfile = PIDFILE self.daemonize = false self.environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end + + def pidfile + @pidfile || (daemonize ? PIDFILE : nil) + end end end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 6726d3c..043f44a 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -1,15 +1,42 @@ require 'spec_helper' describe Crono::Config do + let(:config) { Crono::Config.new } describe '#initialize' do it 'should initialize with default configuration options' do ENV['RAILS_ENV'] = 'test' @config = Crono::Config.new expect(@config.cronotab).to be Crono::Config::CRONOTAB expect(@config.logfile).to be Crono::Config::LOGFILE - expect(@config.pidfile).to be Crono::Config::PIDFILE + expect(@config.pidfile).to be nil expect(@config.daemonize).to be false expect(@config.environment).to be_eql ENV['RAILS_ENV'] end + + describe "#pidfile" do + subject(:pidfile) { config.pidfile } + + context "not explicity configured" do + context "daemonize is false" do + before { config.daemonize = false } + + specify { expect(pidfile).to be_nil } + end + + context "daemonize is true" do + before { config.daemonize = true } + + specify { expect(pidfile).to eq Crono::Config::PIDFILE } + end + end + + context "explicity configured" do + let(:path) { "foo/bar/pid.pid" } + + before { config.pidfile = path } + + specify { expect(pidfile).to eq path } + end + end end end From 4aeb29891eeca79e8679b0ff3702a9c906f0b3f5 Mon Sep 17 00:00:00 2001 From: MichaelAChrisco Date: Fri, 3 Apr 2015 10:50:24 -0700 Subject: [PATCH 4/5] Rake Tasks --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 8832126..180a8e5 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,33 @@ class TestJob # This is not an Active Job job, but pretty legal Crono job. end ``` +Here's an example of a Rake Task within a job: + +```ruby +# config/cronotab.rb +require 'rake' +# Be sure to change AppName to your application name! +AppName::Application.load_tasks + +class Test + def perform + Rake::Task['crono:hello'].invoke + end +end + +Crono.perform(Test).every 5.seconds +``` +With the rake task of: +```Ruby +# lib/tasks/test.rake +namespace :crono do + desc 'Update all tables' + task :hello => :environment do + puts "hello" + end +end +``` + _Please note that crono uses threads, so your code should be thread-safe_ #### Job Schedule From c74291a001920dd0d0c6836f78c1e73c6687d284 Mon Sep 17 00:00:00 2001 From: MichaelAChrisco Date: Fri, 3 Apr 2015 15:26:59 -0700 Subject: [PATCH 5/5] multiple view states --- spec/web_spec.rb | 12 ++++++++++++ web/views/dashboard.haml | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/web_spec.rb b/spec/web_spec.rb index 5e2590e..fb5bc76 100644 --- a/spec/web_spec.rb +++ b/spec/web_spec.rb @@ -29,6 +29,18 @@ describe Crono::Web do get '/' expect(last_response.body).to include 'Error' end + + it 'should show a success mark when a job is healthy' do + @test_job.update(healthy: true) + get '/' + expect(last_response.body).to include 'Success' + end + + it 'should show a pending mark when a job is pending' do + @test_job.update(healthy: nil) + get '/' + expect(last_response.body).to include 'Pending' + end end describe '/job/:id' do diff --git a/web/views/dashboard.haml b/web/views/dashboard.haml index 69f0f5e..5ee4d35 100644 --- a/web/views/dashboard.haml +++ b/web/views/dashboard.haml @@ -6,7 +6,7 @@ %tr %th Job %th Last performed at - %th + %th Status %th - @jobs.each do |job| %tr @@ -16,6 +16,12 @@ - if job.healthy == false %a{ href: url("/job/#{job.id}") } %span.label.label-danger Error + - if job.healthy == true + %a{ href: url("/job/#{job.id}") } + %span.label.label-success Success + - else + %a{ href: url("/job/#{job.id}") } + %span.label.label-default Pending %td %a{ href: url("/job/#{job.id}") } Log