crono 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0045e60df85bab889a28dd9de6563cbb4f9797d0
4
- data.tar.gz: c282718940378a5d41fe75e73780149b46f75a62
3
+ metadata.gz: c146a6ca9be59f261b40b2716337e6db97962c60
4
+ data.tar.gz: f0889fab37a17460d0c676dead916f0c36e315ac
5
5
  SHA512:
6
- metadata.gz: 9b983b15c72eb8f1f813eb0744d51ca286ac8b35f9a35d1bdffb89b297358f4ecc5916a816410609ae0c6c132122c67c546cefc61092c3e0e309614449a33f8e
7
- data.tar.gz: f5fd72d6addae0d7d800ef7b266d01fa47ee1eb28aae9e24add2a1a9b6fcef95ec5fe9961d74b6040e406afbaed10f083db9ec7336c4a680f9e84b881c3b4f40
6
+ metadata.gz: 5498ec9e3ef28a21fa38ffb372d6807f7e34bd4088346a6381151dabf925a26b68857b6c5d5ba74af092a2470a6afc47844875d5c700775d4843d75f0678e614
7
+ data.tar.gz: f4b21a9fe445df51770cff88da34a888fa3e03666c1371b74efe45267c2c0f4d44cba76ebb3571e6e644be366da78c7b41f89114cfe3c51dae91f7c10e91dd84
@@ -0,0 +1,9 @@
1
+ 0.5.0
2
+ -----------
3
+
4
+ - Initial release!
5
+
6
+ 0.5.1
7
+ ———————————
8
+
9
+ - Added -e/--environment ENV option to set the daemon rails environment.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crono (0.0.1)
4
+ crono (0.5.1)
5
5
  activejob (~> 4.0)
6
6
  activesupport (~> 4.0)
7
7
 
data/README.md CHANGED
@@ -1,15 +1,22 @@
1
1
  Crono — Job scheduler for Rails
2
2
  ------------------------
3
+ [![Gem Version](https://badge.fury.io/rb/crono.svg)](http://badge.fury.io/rb/crono)
3
4
  [![Build Status](https://travis-ci.org/plashchynski/crono.svg?branch=master)](https://travis-ci.org/plashchynski/crono)
4
5
  [![Code Climate](https://codeclimate.com/github/plashchynski/crono/badges/gpa.svg)](https://codeclimate.com/github/plashchynski/crono)
5
6
  [![security](https://hakiri.io/github/plashchynski/crono/master.svg)](https://hakiri.io/github/plashchynski/crono/master)
7
+ [![Join the chat at https://gitter.im/plashchynski/crono](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/plashchynski/crono?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
8
 
7
- Crono is a time-based background job scheduler daemon (just like Cron) for Ruby on Rails. It's pure Ruby. It doesn't use Unix Cron and other platform-dependent things. So you can use it everywhere.
9
+ Crono is a time-based background job scheduler daemon (just like Cron) for Ruby on Rails.
10
+
11
+
12
+ ## The Idea
13
+
14
+ Currently there is no such thing as Cron in Ruby for Rails. Well, there's [Whenever](https://github.com/javan/whenever) but it works on top of Unix Cron, so you have no total control of it from Ruby. Crono is pure Ruby. It doesn't use Unix Cron and other platform-dependent things. So you can use it on all platforms supported by Ruby. You have total control of jobs performing process. You have the code in Ruby, so you can understand and modify it to fit your needs.
8
15
 
9
16
 
10
17
  ## Requirements
11
18
 
12
- Tested with latest MRI Ruby (2.2, 2.1 and 2.0) and Rails 3.2+
19
+ Tested with latest MRI Ruby (2.2, 2.1 and 2.0) and Rails 3.2+
13
20
  Other versions are untested but might work fine.
14
21
 
15
22
 
@@ -19,12 +26,12 @@ Add the following line to your application's Gemfile:
19
26
 
20
27
  gem 'crono'
21
28
 
22
- Run the bundle command to install it.
29
+ Run the bundle command to install it.
23
30
  After you install Crono, you can run the generator:
24
31
 
25
32
  rails generate crono:install
26
33
 
27
- It will create a configuration file `config/cronotab.rb`
34
+ It will create a configuration file `config/cronotab.rb`
28
35
  Now you are ready to move forward to create a job and schedule it.
29
36
 
30
37
 
@@ -32,7 +39,7 @@ Now you are ready to move forward to create a job and schedule it.
32
39
 
33
40
  #### Create Job
34
41
 
35
- Crono can use Active Job jobs in `app/jobs/`. The only requirements is that the `perform` method should take no arguments.
42
+ Crono can use Active Job jobs from `app/jobs/`. The only requirements is that the `perform` method should take no arguments.
36
43
 
37
44
  Here's an example of a test job:
38
45
  app/jobs/test_job.rb
@@ -44,9 +51,9 @@ app/jobs/test_job.rb
44
51
  end
45
52
  end
46
53
 
47
- The Active Job jobs is convenient because you can use one class in both periodic and enqueued ways. But it doesn't necessarily. Any class can be used as Job if it has a method `perform` without arguments:
54
+ The ActiveJob jobs is convenient because you can use one job in both periodic and enqueued ways. But Active Job is not required. Any class can be used as a crono job if it implements a method `perform` without arguments:
48
55
 
49
- class TestJob # this is not active job class
56
+ class TestJob # This is not an Active Job job, but pretty legal Crono job.
50
57
  def perform
51
58
  # put you scheduled code here
52
59
  # Comments.deleted.clean_up...
@@ -54,20 +61,20 @@ The Active Job jobs is convenient because you can use one class in both periodic
54
61
  end
55
62
 
56
63
 
57
- #### Schedule Jobs
64
+ #### Job Schedule
58
65
 
59
- The schedule described in the configuration file `config/cronotab.rb`, that we created using `rails generate crono:install` or manually. The semantic is pretty straightforward:
66
+ The schedule described in the configuration file `config/cronotab.rb`, that created using `crono:install` or manually. The semantic is pretty straightforward:
60
67
 
61
68
  Crono.perform(TestJob).every 2.days, at: "15:30"
62
69
 
63
- You can schedule one job a few times if you want the job to be performed a few times a day:
70
+ You can schedule one job a few times, if you want a job to be performed a few times a day:
64
71
 
65
- Crono.perform(TestJob).every 1.days, at: "00:00"
66
- Crono.perform(TestJob).every 1.days, at: "12:00"
72
+ Crono.perform(TestJob).every 1.day, at: "00:00"
73
+ Crono.perform(TestJob).every 1.day, at: "12:00"
67
74
 
68
75
  The `at` can be a Hash:
69
76
 
70
- Crono.perform(TestJob).every 1.days, at: {hour: 12, min: 15}
77
+ Crono.perform(TestJob).every 1.day, at: {hour: 12, min: 15}
71
78
 
72
79
 
73
80
  #### Run daemon
@@ -76,9 +83,21 @@ To run Crono daemon, in your Rails project root directory:
76
83
 
77
84
  bundle exec crono RAILS_ENV=development
78
85
 
86
+ crono usage:
87
+ ```
88
+ Usage: crono [options]
89
+ -C, --cronotab PATH Path to cronotab file (Default: config/cronotab.rb)
90
+ -L, --logfile PATH Path to writable logfile (Default: log/crono.log)
91
+ -P, --pidfile PATH Path to pidfile (Default: tmp/pids/crono.pid)
92
+ -d, --[no-]daemonize Daemonize process (Default: false)
93
+ -e, --environment ENV Application environment (Default: development)
94
+ ```
95
+
96
+ ## Capistrano
97
+ Use the `capistrano-crono` gem ([github](https://github.com/plashchynski/capistrano-crono/)).
79
98
 
80
99
  ## License
81
100
 
82
101
  Copyright 2015 Dzmitry Plashchynski <plashchynski@gmail.com>
83
102
  Licensed under the Apache License, Version 2.0
84
- Please see [LICENSE](https://github.com/plashchynski/crono/blob/master/LICENSE) for licensing details.
103
+ Please see [LICENSE](https://github.com/plashchynski/crono/blob/master/LICENSE) for licensing details.
@@ -0,0 +1,6 @@
1
+ check process crono_myapp
2
+ with pidfile /path/to/crono.pid
3
+ start program = "bundle exec crono" with timeout 30 seconds
4
+ stop program = "kill -s TERM `cat /path/to/crono.pid`" with timeout 30 seconds
5
+ if totalmem is greater than 500 MB for 2 cycles then restart
6
+ group myapp_crono
@@ -53,6 +53,7 @@ module Crono
53
53
  end
54
54
 
55
55
  def load_rails
56
+ ENV['RACK_ENV'] = ENV['RAILS_ENV'] = config.environment
56
57
  require 'rails'
57
58
  require File.expand_path("config/environment.rb")
58
59
  ::Rails.application.eager_load!
@@ -91,7 +92,10 @@ module Crono
91
92
  opts.on("-d", "--[no-]daemonize", "Daemonize process (Default: #{config.daemonize})") do |daemonize|
92
93
  config.daemonize = daemonize
93
94
  end
94
-
95
+
96
+ opts.on '-e', '--environment ENV', "Application environment (Default: #{config.environment})" do |env|
97
+ config.environment = env
98
+ end
95
99
  end.parse!(argv)
96
100
  end
97
101
  end
@@ -8,12 +8,14 @@ module Crono
8
8
  attr_accessor :logfile
9
9
  attr_accessor :pidfile
10
10
  attr_accessor :daemonize
11
+ attr_accessor :environment
11
12
 
12
13
  def initialize
13
14
  self.cronotab = CRONOTAB
14
15
  self.logfile = LOGFILE
15
16
  self.pidfile = PIDFILE
16
17
  self.daemonize = false
18
+ self.environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development"
17
19
  end
18
20
  end
19
21
  end
@@ -1,3 +1,3 @@
1
1
  module Crono
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -49,5 +49,10 @@ describe Crono::CLI do
49
49
  cli.send(:parse_options, ["--daemonize"])
50
50
  expect(cli.config.daemonize).to be true
51
51
  end
52
+
53
+ it "should set environment" do
54
+ cli.send(:parse_options, ["--environment", "production"])
55
+ expect(cli.config.environment).to be_eql("production")
56
+ end
52
57
  end
53
58
  end
@@ -3,11 +3,13 @@ require "spec_helper"
3
3
  describe Crono::Config do
4
4
  describe "#initialize" do
5
5
  it "should initialize with default configuration options" do
6
+ ENV["RAILS_ENV"] = "test"
6
7
  @config = Crono::Config.new
7
8
  expect(@config.cronotab).to be Crono::Config::CRONOTAB
8
9
  expect(@config.logfile).to be Crono::Config::LOGFILE
9
10
  expect(@config.pidfile).to be Crono::Config::PIDFILE
10
11
  expect(@config.daemonize).to be false
12
+ expect(@config.environment).to be_eql ENV["RAILS_ENV"]
11
13
  end
12
14
  end
13
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crono
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Plashchynski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-03 00:00:00.000000000 Z
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -105,6 +105,7 @@ files:
105
105
  - ".gitignore"
106
106
  - ".rspec"
107
107
  - ".travis.yml"
108
+ - Changes.md
108
109
  - Gemfile
109
110
  - Gemfile.lock
110
111
  - LICENSE
@@ -113,6 +114,7 @@ files:
113
114
  - Rakefile
114
115
  - bin/crono
115
116
  - crono.gemspec
117
+ - examples/monitrc.conf
116
118
  - lib/crono.rb
117
119
  - lib/crono/cli.rb
118
120
  - lib/crono/config.rb