mirror of
https://github.com/plashchynski/crono.git
synced 2026-01-16 07:06:39 +01:00
Compare commits
13 Commits
next_jobs_
...
v0.8.5.pre
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50aec2ea87 | ||
|
|
aaa8bc40e5 | ||
|
|
a11a8985c3 | ||
|
|
b010b7349f | ||
|
|
cd5813049c | ||
|
|
c74291a001 | ||
|
|
4aeb29891e | ||
|
|
4415211100 | ||
|
|
4b28f3dd80 | ||
|
|
48db3ef245 | ||
|
|
01a761d919 | ||
|
|
75f1b43c84 | ||
|
|
13ab4838e7 |
12
.gitignore
vendored
12
.gitignore
vendored
@@ -1,4 +1,8 @@
|
||||
pkg/*
|
||||
*.gem
|
||||
.bundle
|
||||
tmp/*.sqlite3
|
||||
/.bundle/
|
||||
/.yardoc
|
||||
/_yardoc/
|
||||
/coverage/
|
||||
/doc/
|
||||
/pkg/
|
||||
/spec/reports/
|
||||
/tmp/
|
||||
|
||||
4
Gemfile
4
Gemfile
@@ -1,2 +1,4 @@
|
||||
source "https://rubygems.org"
|
||||
source 'https://rubygems.org'
|
||||
|
||||
# Specify your gem's dependencies in crono.gemspec
|
||||
gemspec
|
||||
|
||||
12
Gemfile.lock
12
Gemfile.lock
@@ -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)
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
|
||||
3
Rakefile
3
Rakefile
@@ -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
14
bin/console
Executable 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
7
bin/setup
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Crono
|
||||
VERSION = '0.8.1'
|
||||
VERSION = '0.8.5.pre'
|
||||
end
|
||||
|
||||
@@ -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
7
spec/crono_spec.rb
Normal 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
|
||||
@@ -1,6 +1,8 @@
|
||||
require 'bundler/setup'
|
||||
Bundler.setup
|
||||
|
||||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
||||
|
||||
require 'timecop'
|
||||
require 'byebug'
|
||||
require 'crono'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user