Compare commits

...

13 Commits

Author SHA1 Message Date
Dzmitry Plashchynski
50aec2ea87 0.8.5.pre 2015-04-11 18:50:02 +03:00
Dzmitry Plashchynski
aaa8bc40e5 Apply bundler gem template recommendations 2015-04-11 18:48:54 +03:00
Dzmitry Plashchynski
a11a8985c3 Merge branch 'master' of github.com:plashchynski/crono 2015-04-11 18:24:07 +03:00
Dzmitry Plashchynski
b010b7349f Merge pull request #18 from michaelachrisco/view-multiple-states
Multiple View States
2015-04-04 19:07:21 +03:00
Dzmitry Plashchynski
cd5813049c Merge pull request #15 from michaelachrisco/rake_tasks
Readme Rake Tasks
2015-04-04 18:34:19 +03:00
MichaelAChrisco
c74291a001 multiple view states 2015-04-03 15:26:59 -07:00
MichaelAChrisco
4aeb29891e Rake Tasks 2015-04-03 14:11:26 -07:00
Dzmitry Plashchynski
4415211100 Merge pull request #13 from thomasfedb/daemon-pidfile-default
Default to not writing a pidfile unless daemonized
2015-04-02 17:59:19 +03:00
Thomas Drake-Brockman
4b28f3dd80 Updated CLI and Config to default to not writing a pidfile unless daemonized. 2015-04-02 03:14:08 +08:00
Dzmitry Plashchynski
48db3ef245 Merge pull request #12 from Trevoke/patch-1
Update README.md
2015-03-25 00:07:52 +02:00
Dzmitry Plashchynski
01a761d919 Merge pull request #11 from MiroslavCsonka/master
Update README.md
2015-03-25 00:05:37 +02:00
Aldric Giacomoni
75f1b43c84 Update README.md 2015-03-24 17:58:59 -04:00
Miroslav Csonka
13ab4838e7 Update README.md
Fix ruby typo
2015-03-24 22:51:56 +01:00
18 changed files with 157 additions and 48 deletions

12
.gitignore vendored
View File

@@ -1,4 +1,8 @@
pkg/*
*.gem
.bundle
tmp/*.sqlite3
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

2
.rspec
View File

@@ -1,2 +1,2 @@
--color
--format documentation
--color

View File

@@ -1,2 +1,4 @@
source "https://rubygems.org"
source 'https://rubygems.org'
# Specify your gem's dependencies in crono.gemspec
gemspec

View File

@@ -1,7 +1,7 @@
PATH
remote: .
specs:
crono (0.8.1)
crono (0.8.5.pre)
activejob (~> 4.0)
activerecord (~> 4.0)
activesupport (~> 4.0)
@@ -27,12 +27,9 @@ GEM
tzinfo (~> 1.1)
arel (6.0.0)
builder (3.2.2)
byebug (3.5.1)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
byebug (4.0.5)
columnize (= 0.9.0)
columnize (0.9.0)
debugger-linecache (1.2.0)
diff-lcs (1.2.5)
globalid (0.3.3)
activesupport (>= 4.1.0)
@@ -51,7 +48,7 @@ GEM
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-core (3.2.1)
rspec-core (3.2.2)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.0)
diff-lcs (>= 1.2.0, < 2.0)
@@ -64,7 +61,6 @@ GEM
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slop (3.6.0)
sqlite3 (1.3.10)
thread_safe (0.3.5)
tilt (1.4.1)

View File

@@ -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
@@ -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
```ruby
gam 'haml'
gem 'haml'
gem 'sinatra', require: nil
```

View File

@@ -1,5 +1,4 @@
require 'bundler'
Bundler::GemHelper.install_tasks
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new('spec')

14
bin/console Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env ruby
require "bundler/setup"
require "crono"
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
require "irb"
IRB.start

7
bin/setup Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
bundle install
# Do any other automated setup that you need to do here

View File

@@ -1,32 +1,34 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/crono/version', __FILE__)
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'crono/version'
Gem::Specification.new do |s|
s.name = 'crono'
s.version = Crono::VERSION
s.authors = ['Dzmitry Plashchynski']
s.email = ['plashchynski@gmail.com']
s.homepage = 'https://github.com/plashchynski/crono'
s.description = s.summary = 'Job scheduler for Rails'
s.license = 'Apache-2.0'
Gem::Specification.new do |spec|
spec.name = 'crono'
spec.version = Crono::VERSION
spec.authors = ['Dzmitry Plashchynski']
spec.email = ['plashchynski@gmail.com']
s.required_rubygems_version = '>= 1.3.6'
s.rubyforge_project = 'crono'
spec.summary = 'Job scheduler for Rails'
spec.description = 'A time-based background job scheduler daemon (just like Cron) for Rails'
spec.homepage = 'https://github.com/plashchynski/crono'
spec.license = 'Apache-2.0'
s.add_runtime_dependency 'activejob', '~> 4.0'
s.add_runtime_dependency 'activesupport', '~> 4.0'
s.add_runtime_dependency 'activerecord', '~> 4.0'
s.add_development_dependency 'rake', '~> 10.0'
s.add_development_dependency 'bundler', '>= 1.0.0'
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'timecop', '~> 0.7'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'byebug'
s.add_development_dependency 'sinatra'
s.add_development_dependency 'haml'
s.add_development_dependency 'rack-test'
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe' # http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
s.files = `git ls-files`.split("\n")
s.executables = ['crono']
s.require_path = 'lib'
spec.add_runtime_dependency 'activejob', '~> 4.0'
spec.add_runtime_dependency 'activesupport', '~> 4.0'
spec.add_runtime_dependency 'activerecord', '~> 4.0'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'bundler', '>= 1.0.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'timecop', '~> 0.7'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'byebug'
spec.add_development_dependency 'sinatra'
spec.add_development_dependency 'haml'
spec.add_development_dependency 'rack-test'
end

View File

@@ -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

View File

@@ -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

View File

@@ -1,3 +1,3 @@
module Crono
VERSION = '0.8.1'
VERSION = '0.8.5.pre'
end

View File

@@ -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

7
spec/crono_spec.rb Normal file
View File

@@ -0,0 +1,7 @@
require 'spec_helper'
describe Crono do
it 'has a version number' do
expect(Crono::VERSION).not_to be nil
end
end

View File

@@ -1,6 +1,8 @@
require 'bundler/setup'
Bundler.setup
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'timecop'
require 'byebug'
require 'crono'

View File

@@ -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

View File

@@ -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