mirror of
https://github.com/plashchynski/crono.git
synced 2026-04-24 01:38:37 +02:00
Merge branch 'master' of github.com:plashchynski/crono
This commit is contained in:
29
README.md
29
README.md
@@ -72,6 +72,33 @@ class TestJob # This is not an Active Job job, but pretty legal Crono job.
|
|||||||
end
|
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_
|
_Please note that crono uses threads, so your code should be thread-safe_
|
||||||
|
|
||||||
#### Job Schedule
|
#### Job Schedule
|
||||||
@@ -120,7 +147,7 @@ Crono comes with a Sinatra application that can display the current state of Cro
|
|||||||
Add `sinatra` and `haml` to your Gemfile
|
Add `sinatra` and `haml` to your Gemfile
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
gam 'haml'
|
gem 'haml'
|
||||||
gem 'sinatra', require: nil
|
gem 'sinatra', require: nil
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ module Crono
|
|||||||
end
|
end
|
||||||
|
|
||||||
def write_pid
|
def write_pid
|
||||||
|
return unless config.pidfile
|
||||||
pidfile = File.expand_path(config.pidfile)
|
pidfile = File.expand_path(config.pidfile)
|
||||||
File.write(pidfile, ::Process.pid)
|
File.write(pidfile, ::Process.pid)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,9 +10,12 @@ module Crono
|
|||||||
def initialize
|
def initialize
|
||||||
self.cronotab = CRONOTAB
|
self.cronotab = CRONOTAB
|
||||||
self.logfile = LOGFILE
|
self.logfile = LOGFILE
|
||||||
self.pidfile = PIDFILE
|
|
||||||
self.daemonize = false
|
self.daemonize = false
|
||||||
self.environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
self.environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pidfile
|
||||||
|
@pidfile || (daemonize ? PIDFILE : nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,15 +1,42 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Crono::Config do
|
describe Crono::Config do
|
||||||
|
let(:config) { Crono::Config.new }
|
||||||
describe '#initialize' do
|
describe '#initialize' do
|
||||||
it 'should initialize with default configuration options' do
|
it 'should initialize with default configuration options' do
|
||||||
ENV['RAILS_ENV'] = 'test'
|
ENV['RAILS_ENV'] = 'test'
|
||||||
@config = Crono::Config.new
|
@config = Crono::Config.new
|
||||||
expect(@config.cronotab).to be Crono::Config::CRONOTAB
|
expect(@config.cronotab).to be Crono::Config::CRONOTAB
|
||||||
expect(@config.logfile).to be Crono::Config::LOGFILE
|
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.daemonize).to be false
|
||||||
expect(@config.environment).to be_eql ENV['RAILS_ENV']
|
expect(@config.environment).to be_eql ENV['RAILS_ENV']
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,6 +29,18 @@ describe Crono::Web do
|
|||||||
get '/'
|
get '/'
|
||||||
expect(last_response.body).to include 'Error'
|
expect(last_response.body).to include 'Error'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '/job/:id' do
|
describe '/job/:id' do
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
%tr
|
%tr
|
||||||
%th Job
|
%th Job
|
||||||
%th Last performed at
|
%th Last performed at
|
||||||
%th
|
%th Status
|
||||||
%th
|
%th
|
||||||
- @jobs.each do |job|
|
- @jobs.each do |job|
|
||||||
%tr
|
%tr
|
||||||
@@ -16,6 +16,12 @@
|
|||||||
- if job.healthy == false
|
- if job.healthy == false
|
||||||
%a{ href: url("/job/#{job.id}") }
|
%a{ href: url("/job/#{job.id}") }
|
||||||
%span.label.label-danger Error
|
%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
|
%td
|
||||||
%a{ href: url("/job/#{job.id}") }
|
%a{ href: url("/job/#{job.id}") }
|
||||||
Log
|
Log
|
||||||
|
|||||||
Reference in New Issue
Block a user