crono 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +2 -3
- data/Rakefile +3 -4
- data/app/assets/javascripts/crono/materialize.min.js +6 -0
- data/app/assets/stylesheets/crono/application.css +26 -0
- data/app/assets/stylesheets/crono/materialize.min.css +31 -0
- data/app/controllers/crono/application_controller.rb +5 -0
- data/app/controllers/crono/jobs_controller.rb +11 -0
- data/app/models/crono/application_record.rb +5 -0
- data/{lib/crono/orm/active_record → app/models/crono}/crono_job.rb +1 -2
- data/app/views/crono/jobs/index.html.erb +50 -0
- data/app/views/crono/jobs/show.html.erb +16 -0
- data/app/views/layouts/crono/application.html.erb +31 -0
- data/{exe → bin}/crono +0 -0
- data/config/routes.rb +4 -0
- data/lib/crono/cli.rb +3 -20
- data/lib/crono/config.rb +2 -3
- data/lib/crono/engine.rb +15 -0
- data/lib/crono/job.rb +10 -6
- data/lib/crono/performer_proxy.rb +2 -2
- data/lib/crono/period.rb +6 -5
- data/lib/crono/time_of_day.rb +2 -2
- data/lib/crono/version.rb +1 -1
- data/lib/crono.rb +3 -3
- data/lib/generators/crono/install/install_generator.rb +12 -1
- data/lib/generators/crono/install/templates/migrations/create_crono_jobs.rb +2 -6
- data/spec/assets/bad_cronotab.rb +12 -0
- data/spec/assets/good_cronotab.rb +9 -0
- data/spec/cli_spec.rb +109 -0
- data/spec/config_spec.rb +47 -0
- data/spec/crono_spec.rb +7 -0
- data/spec/cronotab_spec.rb +20 -0
- data/spec/internal/:memory +0 -0
- data/{log/.keep → spec/internal/app/assets/config/manifest.js} +0 -0
- data/spec/internal/app/controllers/application_controller.rb +3 -0
- data/spec/internal/app/controllers/pages_controller.rb +5 -0
- data/spec/internal/app/views/pages/index.html.erb +1 -0
- data/spec/internal/config/application.rb +22 -0
- data/spec/internal/config/boot.rb +5 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/environment.rb +2 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/config/storage.yml +3 -0
- data/spec/internal/db/crono_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +10 -0
- data/spec/internal/log/test.log +3868 -0
- data/{tmp/.gitkeep → spec/internal/public/favicon.ico} +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/-5/-5qRtN26mFn5ud6yyw5E5MpFhT61YcDJPMTlAoDLkEs.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/-C/-C4fFLLfC1HB9flvtZbgPTj9oNiDtq1bvp8LPbnRv1k.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/01/01tpm-y3svQKpsPvOHFWMxWBaG_35EVrgmnB5HKppZw.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/0K/0KEVKDTACcfyL6Fl5QZ6qSNOeswfd6FloUlWXQvwsHg.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/1F/1FwwOzgRWJEUxIctLIsrhuh9z3QKl1XWDCcdfRhgKPk.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/1n/1n5Wp1qC4BYhgEaXBnkRpO1N0oVAwLVdn47Ebk5nduY.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/22/22NEh4OGcNmK5Qh9ss73s622T6309DH8zv5ABF6-6Uk.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/2n/2nEu77IGZHZPjlliLtJofREUZgmt-DGEhQnGIDMd0vA.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/2q/2qyBEUowJIKm_1EF_tbDWLjGDvVCbTjiHtRX_PEVn-U.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/3k/3khLNNSEoPg-2idoNmihX2Ba1loklzJsXvSRXujPaRk.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/7A/7A_YhyGyNk4Me5J0-p-XwK0qelTclb_2WX5pq0eY9dY.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/8d/8daZARHc9PDr5TZ5fqfR-_vJ5kCRzsZQKhQxFkrg_XI.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/90/90vzKM32bOX3CR_IP7i2_AHgZSmn82XN_9gLyqidtUc.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/9V/9V7dOKixQfEwAEIweL7rD4CUSL51MqiMeB67I5xhwXs.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/9a/9aYqlHyIyZYckdfIJ3GbxrCRrsRgbc0wfZBCfd1lVWE.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Ac/AcdbxQ2RjSGjrVJSdCjS-HN_RI3GZbW86dZGhSD8Ots.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Cj/Cjzu7j1PyqHJD0alH5TiAYfJDN0Zbxhg4zFZegEzuYM.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/DC/DC_euXbiKWPXx4qSkPGLNU4C2RIvjMBWliBrTgl6Mqo.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Db/DboywI_AoqjU7aQB5p90ZP76JW8sinmm4tMgjEG8Iu8.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Dz/DzN3uO_usT53JAsXp4Td8TcNu4kjXPgqTUbLJUG7220.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/F3/F3BxEXMKcd4KO0HPnLrN1g6pJIJ_iQXCz9vW--uEixY.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/FE/FEVuJQTU_YF19u2IzUvuuYlUOoKsyk4JA9kX5UCIelU.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/GG/GGT27f9SL2RsHpi8_pEJ1NHNgLBqDui3sDZOTgeD8z0.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Gj/Gj2Go21wf2SZAnyJXKNSGfiGzYXAtrIdSHB2wuGrB6k.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Hi/HicniSJ1JdM-SmZBY-KtuXL6pubtiugbtOJ-qF07hfk.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Hm/HmvhHkuG82Y4O19j_mfQOw9Q4VEq5hW1Ny0Pzh3gY00.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Ic/IcQIS6wTKG3ZKN6foQYUMxNU4dNQRhrAdwVrAi8u11k.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Kz/KzqcEtJH4QmChDeq7W5WHCOe_NOjqNrAWOzOI0b0RrU.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/LE/LE5Is_h8o9DKajRisizRsovSfpVc8T-Z_xScq0YxBMg.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Mc/Mcvqw-yzpBv2GpUMmKfPZed-6wXUYd8rDdGJ12xAEsA.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Nn/NneCOb3TsKS1FT6ImmBbFe5UuI_LxAmaYyk5o3st8jc.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/Ro/RogqNsDfrMolvoqWLn8lCbweCzxIhN-fgXnLfBMFo8A.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/T9/T9uigSdiu4wxaUieqeBq4uQYRdwGsT2acN15p0osfMU.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/TH/THqp0Tr7zg3pz3WISBe0_u-QcPXHIesH0WlH_6zKzco.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/VF/VFaPzl3--nBqsNzvUgJUt2TjANPLzaelSx_eOc_J090.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/XG/XG0dD9kx-qBYVC-WwhzECOTsSICqvnAqLOCq1JWWrRI.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/ZT/ZTJFqWngu6gOr5GuiqAV52YNHRuJeuwQelNDhtm8pKU.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/ZT/zT_x9gWE8eLO9s8Ul_dtwvAqzekg3DpeuSRkQepkKJ4.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/aW/aWSe6QsJ8Dk7ZAuTOYgjegrAoC2XYQtCCeo9KVzVVQs.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/at/ataSdIHBESkY5GN7sMG-XyOftCkIWDK0QaKEewVkqIU.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/au/aukwvh3eZhFFGyc5qZWT9KMJQHxFrTDEqfjXr4VM4dc.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/bu/bu6XdfzbXfiTnSQ_6Shml3tpB7ovoUAcuCGNs-eYehI.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/c2/c2yubRDZmdi6tFc__QitGtUTkpKt0Goc7FNKhRNw0Uk.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/fu/fuVeiMpLNyElLwjOR6EBQP7-ZUwuJTsQe_Ie11TlX7Y.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/hY/hY9drCAzyxN-KBhXav5VLmk4-AFlKT2yguKNLm7wGsA.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/hg/hgkvHB4OV3E0Gq-Ud_lH2ljTzyb-8nGquMAFTBr4O0o.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/jV/jVXcSpsjtyBHtJaFkxwLVcVm79OT5CVEA9XuzV01O2o.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/kK/kKAy2xIb8ozBaCVqr7LkIsO3-78l5U08uq1Ot7JvES0.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/kU/kUed8S8DBmWvnTdMtg0PzTYj51Rbq9R9yfr6bhPzp2I.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/kw/kwNFhW24nxXy_HfVKYdXJyRqhu7ljgl9wR2DcJUo-nA.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/ls/ls-nV5B50MgpIYfcYZWWWjiNsU2tD2DrEbiiEmGtArk.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/m4/m47fbWgjCvvfU0XLMaGJE1zb9zh2STuMZFp7umYjLTA.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/m_/m_VPZpr_Dhvko_jzP2-4VRhDpknOtciX8pqAq3jY4P8.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/n5/n5rslESPawJxj7Ii3QNWxFl-2sUJE4leiEyzbuFE9Mc.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/nz/nzkJWHKhKCtwI9w3TBcwyGzKEik4UFYwulf2jO7xPXc.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/o4/o42lMuA3eKF-eY5RsJO4kHIGfba2QHOCO0b9rz5iNIU.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/oF/oFrXjOEKX9hseSPY19vWwGHfET4QpdjGD5UdFIEN8mo.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/od/od3K7nGVNq7YsrTVF7ItWWkHs8F_XEGn_BlCD5wW_gc.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/qo/qoEv51qzi0h4mpNP5B4vQydW2FmhC_vbbx6vWJ99Jls.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/tQ/tQ-nAfm23F-ckwkWPuftbJS6tumDQhNxQgPIZSrfPM0.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/tr/trn1zjMZoBOIgSYgI84OzddhfICB2KnU4XbV8axLVGo.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/u3/u3VRW5zPBM7BcNRi3G4B8M6CdscKSLJ3xYmp44ekmjU.cache +0 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/uG/UgcLSZ8AKbE1AYf75cSUXI6uefPECNfBcVQ7L0BDzHg.cache +3 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/uG/uGhNDzX7DxymN3xqHLHTndSae3bN0A-MlTk05m6wV4A.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/wF/wFT7zoeQQwz-V8syWaS01xr7xgZWr3UNQLWbYSKXirw.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/wN/wNw4kAG0E_RrvLeFAizMmTp_0jh-HGw1ONLtRyw92z0.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/x-/x-qCUFpNxK1jTHH2qV_VgVk_KrGKdHzNGOnDMVFstuQ.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/yk/ykU9I1MzGh7clO4pu853ZKl4LtMlDtyr8BjpiozFQ8E.cache +2 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/yk/ykWLbyEuqa0JHcwHJ-SdVxv4ImwnymlVxvbPKtk6HUM.cache +1 -0
- data/spec/internal/tmp/cache/assets/sprockets/v4.0.0/zO/zOr1jCikukgv8-bNHvK43vGLa3CSjtmiwf2K7dUjTnw.cache +0 -0
- data/spec/job_spec.rb +183 -0
- data/spec/models/crono/crono_job_spec.rb +31 -0
- data/spec/performer_proxy_spec.rb +39 -0
- data/spec/period_spec.rb +141 -0
- data/spec/rails_helper.rb +89 -0
- data/spec/scheduler_spec.rb +62 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/tasks/crono_tasks_spec.rb +23 -0
- data/spec/web_spec.rb +61 -0
- metadata +233 -68
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/.travis.yml +0 -14
- data/Changes.md +0 -88
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -78
- data/NOTICE +0 -2
- data/README.md +0 -218
- data/bin/console +0 -14
- data/bin/setup +0 -7
- data/crono.gemspec +0 -34
- data/examples/crono_web_ui.png +0 -0
- data/examples/cronotab.rb +0 -14
- data/examples/monitrc.conf +0 -6
- data/lib/crono/web.rb +0 -22
- data/web/assets/css/custom.css +0 -19
- data/web/assets/css/materialize.min.css +0 -16
- data/web/assets/font/material-design-icons/LICENSE.txt +0 -428
- data/web/assets/font/material-design-icons/Material-Design-Icons.eot +0 -0
- data/web/assets/font/material-design-icons/Material-Design-Icons.svg +0 -751
- data/web/assets/font/material-design-icons/Material-Design-Icons.ttf +0 -0
- data/web/assets/font/material-design-icons/Material-Design-Icons.woff +0 -0
- data/web/assets/font/material-design-icons/Material-Design-Icons.woff2 +0 -0
- data/web/assets/font/roboto/Roboto-Bold.ttf +0 -0
- data/web/assets/font/roboto/Roboto-Bold.woff +0 -0
- data/web/assets/font/roboto/Roboto-Bold.woff2 +0 -0
- data/web/assets/font/roboto/Roboto-Light.ttf +0 -0
- data/web/assets/font/roboto/Roboto-Light.woff +0 -0
- data/web/assets/font/roboto/Roboto-Light.woff2 +0 -0
- data/web/assets/font/roboto/Roboto-Medium.ttf +0 -0
- data/web/assets/font/roboto/Roboto-Medium.woff +0 -0
- data/web/assets/font/roboto/Roboto-Medium.woff2 +0 -0
- data/web/assets/font/roboto/Roboto-Regular.ttf +0 -0
- data/web/assets/font/roboto/Roboto-Regular.woff +0 -0
- data/web/assets/font/roboto/Roboto-Regular.woff2 +0 -0
- data/web/assets/font/roboto/Roboto-Thin.ttf +0 -0
- data/web/assets/font/roboto/Roboto-Thin.woff +0 -0
- data/web/assets/font/roboto/Roboto-Thin.woff2 +0 -0
- data/web/assets/js/jquery-2.1.3.min.js +0 -4
- data/web/assets/js/materialize.min.js +0 -10
- data/web/views/dashboard.haml +0 -36
- data/web/views/job.haml +0 -15
- data/web/views/layout.haml +0 -29
data/README.md
DELETED
@@ -1,218 +0,0 @@
|
|
1
|
-
Crono — Job scheduler for Rails
|
2
|
-
------------------------
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/crono.svg)](http://badge.fury.io/rb/crono)
|
4
|
-
[![Build Status](https://travis-ci.org/plashchynski/crono.svg?branch=master)](https://travis-ci.org/plashchynski/crono)
|
5
|
-
[![Code Climate](https://codeclimate.com/github/plashchynski/crono/badges/gpa.svg)](https://codeclimate.com/github/plashchynski/crono)
|
6
|
-
[![security](https://hakiri.io/github/plashchynski/crono/master.svg)](https://hakiri.io/github/plashchynski/crono/master)
|
7
|
-
|
8
|
-
Crono is a time-based background job scheduler daemon (just like Cron) for Ruby on Rails.
|
9
|
-
|
10
|
-
|
11
|
-
## The Purpose
|
12
|
-
|
13
|
-
Currently, there is no such thing as Ruby Cron for Rails. Well, there's [Whenever](https://github.com/javan/whenever) but it works on top of Unix Cron, so you can't manage 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. It persists job states to your database using Active Record. You have full control of jobs performing process. It's Ruby, so you can understand and modify it to fit your needs.
|
14
|
-
|
15
|
-
![Web UI](https://github.com/plashchynski/crono/raw/master/examples/crono_web_ui.png)
|
16
|
-
|
17
|
-
|
18
|
-
## Requirements
|
19
|
-
|
20
|
-
Tested with latest MRI Ruby 2.2+, 2.3+, Rails 4.\*, and Rails 5.\*.
|
21
|
-
Other versions are untested but might work fine.
|
22
|
-
|
23
|
-
|
24
|
-
## Installation
|
25
|
-
|
26
|
-
Add the following line to your application's Gemfile:
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
gem 'crono'
|
30
|
-
```
|
31
|
-
|
32
|
-
Run the `bundle` command to install it.
|
33
|
-
After you install Crono, you can run the generator:
|
34
|
-
|
35
|
-
rails generate crono:install
|
36
|
-
|
37
|
-
It will create a configuration file `config/cronotab.rb` and migration
|
38
|
-
Run the migration:
|
39
|
-
|
40
|
-
rake db:migrate
|
41
|
-
|
42
|
-
Now you are ready to move forward to create a job and schedule it.
|
43
|
-
|
44
|
-
|
45
|
-
## Usage
|
46
|
-
|
47
|
-
#### Create Job
|
48
|
-
|
49
|
-
Crono can use Active Job jobs from `app/jobs/`. The only requirement is that the `perform` method should take no arguments.
|
50
|
-
|
51
|
-
Here's an example of a job:
|
52
|
-
|
53
|
-
```ruby
|
54
|
-
# app/jobs/test_job.rb
|
55
|
-
class TestJob < ActiveJob::Base
|
56
|
-
def perform
|
57
|
-
# put you scheduled code here
|
58
|
-
# Comments.deleted.clean_up...
|
59
|
-
end
|
60
|
-
end
|
61
|
-
```
|
62
|
-
|
63
|
-
The ActiveJob jobs are 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`:
|
64
|
-
|
65
|
-
```ruby
|
66
|
-
class TestJob # This is not an Active Job job, but pretty legal Crono job.
|
67
|
-
def perform(*args)
|
68
|
-
# put you scheduled code here
|
69
|
-
# Comments.deleted.clean_up...
|
70
|
-
end
|
71
|
-
end
|
72
|
-
```
|
73
|
-
|
74
|
-
Here's an example of a Rake Task within a job:
|
75
|
-
|
76
|
-
```ruby
|
77
|
-
# config/cronotab.rb
|
78
|
-
require 'rake'
|
79
|
-
|
80
|
-
Rails.app_class.load_tasks
|
81
|
-
|
82
|
-
class Test
|
83
|
-
def perform
|
84
|
-
Rake::Task['crono:hello'].invoke
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
Crono.perform(Test).every 5.seconds
|
89
|
-
```
|
90
|
-
With the rake task of:
|
91
|
-
```Ruby
|
92
|
-
# lib/tasks/test.rake
|
93
|
-
namespace :crono do
|
94
|
-
desc 'Update all tables'
|
95
|
-
task :hello => :environment do
|
96
|
-
puts "hello"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
```
|
100
|
-
|
101
|
-
_Please note that crono uses threads, so your code should be thread-safe_
|
102
|
-
|
103
|
-
#### Job Schedule
|
104
|
-
|
105
|
-
Schedule list is defined in the file `config/cronotab.rb`, that created using `crono:install`. The semantic is pretty straightforward:
|
106
|
-
|
107
|
-
```ruby
|
108
|
-
# config/cronotab.rb
|
109
|
-
Crono.perform(TestJob).every 2.days, at: {hour: 15, min: 30}
|
110
|
-
Crono.perform(TestJob).every 1.week, on: :monday, at: "15:30"
|
111
|
-
```
|
112
|
-
|
113
|
-
You can schedule one job a few times if you want the job to be performed a few times a day or a week:
|
114
|
-
|
115
|
-
```ruby
|
116
|
-
Crono.perform(TestJob).every 1.week, on: :monday
|
117
|
-
Crono.perform(TestJob).every 1.week, on: :thursday
|
118
|
-
```
|
119
|
-
|
120
|
-
The `at` can be a Hash:
|
121
|
-
|
122
|
-
```ruby
|
123
|
-
Crono.perform(TestJob).every 1.day, at: {hour: 12, min: 15}
|
124
|
-
```
|
125
|
-
|
126
|
-
You can schedule a job with arguments, which can contain objects that can be
|
127
|
-
serialized using JSON.generate
|
128
|
-
|
129
|
-
```ruby
|
130
|
-
Crono.perform(TestJob, 'some', 'args').every 1.day, at: {hour: 12, min: 15}
|
131
|
-
```
|
132
|
-
|
133
|
-
You can set some options that not passed to the job but affect how the job will be treated by Crono. For example, you can set to truncate job logs (which stored in the database) to a certain number of records:
|
134
|
-
|
135
|
-
```ruby
|
136
|
-
Crono.perform(TestJob).with_options(truncate_log: 100).every 1.week, on: :monday
|
137
|
-
```
|
138
|
-
|
139
|
-
#### Run
|
140
|
-
|
141
|
-
To run Crono, in your Rails project root directory:
|
142
|
-
|
143
|
-
bundle exec crono RAILS_ENV=development
|
144
|
-
|
145
|
-
crono usage:
|
146
|
-
```
|
147
|
-
Usage: crono [options] [start|stop|restart|run]
|
148
|
-
-C, --cronotab PATH Path to cronotab file (Default: config/cronotab.rb)
|
149
|
-
-L, --logfile PATH Path to writable logfile (Default: log/crono.log)
|
150
|
-
-P, --pidfile PATH Deprecated! use --piddir with --process_name; Path to pidfile (Default: )
|
151
|
-
-D, --piddir PATH Path to piddir (Default: tmp/pids)
|
152
|
-
-N, --process_name NAME Name of the process (Default: crono)
|
153
|
-
-d, --[no-]daemonize Deprecated! Instead use crono [start|stop|restart] without this option; Daemonize process (Default: false)
|
154
|
-
-m, --monitor Start monitor process for a deamon (Default false)
|
155
|
-
-e, --environment ENV Application environment (Default: development)
|
156
|
-
```
|
157
|
-
|
158
|
-
#### Run as a daemon
|
159
|
-
|
160
|
-
To run Crono as a daemon, please add to your Gemfile:
|
161
|
-
|
162
|
-
```ruby
|
163
|
-
gem 'daemons'
|
164
|
-
```
|
165
|
-
|
166
|
-
Then:
|
167
|
-
|
168
|
-
bundle install; bundle exec crono start RAILS_ENV=development
|
169
|
-
|
170
|
-
There are "start", "stop", and "restart" commands.
|
171
|
-
|
172
|
-
## Web UI
|
173
|
-
|
174
|
-
Crono comes with a Sinatra application that can display the current state of Crono jobs.
|
175
|
-
Add `sinatra` and `haml` to your Gemfile
|
176
|
-
|
177
|
-
```ruby
|
178
|
-
gem 'haml'
|
179
|
-
gem 'sinatra', require: nil
|
180
|
-
```
|
181
|
-
|
182
|
-
Add the following to your `config/routes.rb`:
|
183
|
-
|
184
|
-
```ruby
|
185
|
-
Rails.application.routes.draw do
|
186
|
-
mount Crono::Web, at: '/crono'
|
187
|
-
...
|
188
|
-
```
|
189
|
-
|
190
|
-
Access management and other questions described in the [wiki](https://github.com/plashchynski/crono/wiki/Web-UI).
|
191
|
-
|
192
|
-
#### Known issues
|
193
|
-
|
194
|
-
For Rails 5, in case of the errors:
|
195
|
-
```
|
196
|
-
`require': cannot load such file -- rack/showexceptions (LoadError)
|
197
|
-
```
|
198
|
-
See the related issue [#52](https://github.com/plashchynski/crono/issues/52)
|
199
|
-
|
200
|
-
|
201
|
-
## Capistrano
|
202
|
-
|
203
|
-
Use the `capistrano-crono` gem ([github](https://github.com/plashchynski/capistrano-crono/)).
|
204
|
-
|
205
|
-
|
206
|
-
## Support
|
207
|
-
|
208
|
-
Feel free to create [issues](https://github.com/plashchynski/crono/issues)
|
209
|
-
|
210
|
-
|
211
|
-
## Known Issues
|
212
|
-
|
213
|
-
* Is not compatible with the `protected_attributes` gem. See: [https://github.com/plashchynski/crono/issues/43](https://github.com/plashchynski/crono/issues/43)
|
214
|
-
|
215
|
-
|
216
|
-
## License
|
217
|
-
|
218
|
-
Please see [LICENSE](https://github.com/plashchynski/crono/blob/master/LICENSE) for licensing details.
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "crono"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
data/bin/setup
DELETED
data/crono.gemspec
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'crono/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'crono'
|
8
|
-
spec.version = Crono::VERSION
|
9
|
-
spec.authors = ['Dzmitry Plashchynski']
|
10
|
-
spec.email = ['plashchynski@gmail.com']
|
11
|
-
|
12
|
-
spec.summary = 'Job scheduler for Rails'
|
13
|
-
spec.description = 'A time-based background job scheduler daemon (just like Cron) for Rails'
|
14
|
-
spec.homepage = 'https://github.com/plashchynski/crono'
|
15
|
-
spec.license = 'Apache-2.0'
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = 'exe' # http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ['lib']
|
21
|
-
|
22
|
-
spec.add_runtime_dependency 'activesupport', '>= 4.0'
|
23
|
-
spec.add_runtime_dependency 'activerecord', '>= 4.0'
|
24
|
-
spec.add_development_dependency 'rake', '>= 10.0'
|
25
|
-
spec.add_development_dependency 'bundler', '>= 1.0.0'
|
26
|
-
spec.add_development_dependency 'rspec', '>= 3.0'
|
27
|
-
spec.add_development_dependency 'timecop', '>= 0.7'
|
28
|
-
spec.add_development_dependency 'sqlite3'
|
29
|
-
spec.add_development_dependency 'byebug'
|
30
|
-
spec.add_development_dependency 'sinatra'
|
31
|
-
spec.add_development_dependency 'haml'
|
32
|
-
spec.add_development_dependency 'rack-test'
|
33
|
-
spec.add_development_dependency 'daemons'
|
34
|
-
end
|
data/examples/crono_web_ui.png
DELETED
Binary file
|
data/examples/cronotab.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# cronotab.rb - Crono configuration file
|
2
|
-
#
|
3
|
-
# Here you can specify periodic jobs and schedule.
|
4
|
-
# You can use ActiveJob's jobs from `app/jobs/`
|
5
|
-
# You can use any class. The only requirement is that
|
6
|
-
# class should have a method `perform` without arguments.
|
7
|
-
#
|
8
|
-
class TestJob
|
9
|
-
def perform
|
10
|
-
puts 'Test!'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
Crono.perform(TestJob).every 2.days, at: '15:30'
|
data/examples/monitrc.conf
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
check process crono_myapp
|
2
|
-
with pidfile /path/to/crono.pid
|
3
|
-
start program = "bundle exec crono -e production" 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
|
data/lib/crono/web.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'haml'
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'crono'
|
4
|
-
|
5
|
-
module Crono
|
6
|
-
# Web is a Web UI Sinatra app
|
7
|
-
class Web < Sinatra::Base
|
8
|
-
set :root, File.expand_path(File.dirname(__FILE__) + '/../../web')
|
9
|
-
set :public_folder, proc { "#{root}/assets" }
|
10
|
-
set :views, proc { "#{root}/views" }
|
11
|
-
|
12
|
-
get '/' do
|
13
|
-
@jobs = Crono::CronoJob.all
|
14
|
-
haml :dashboard, format: :html5
|
15
|
-
end
|
16
|
-
|
17
|
-
get '/job/:id' do
|
18
|
-
@job = Crono::CronoJob.find(params[:id])
|
19
|
-
haml :job
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/web/assets/css/custom.css
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
body {
|
2
|
-
display: -webkit-box;
|
3
|
-
display: -webkit-flex;
|
4
|
-
display: -ms-flexbox;
|
5
|
-
display: flex;
|
6
|
-
min-height: 100vh;
|
7
|
-
-webkit-box-orient: vertical;
|
8
|
-
-webkit-box-direction: normal;
|
9
|
-
-webkit-flex-direction: column;
|
10
|
-
-ms-flex-direction: column;
|
11
|
-
flex-direction: column;
|
12
|
-
}
|
13
|
-
|
14
|
-
main {
|
15
|
-
-webkit-box-flex: 1;
|
16
|
-
-webkit-flex: 1 0 auto;
|
17
|
-
-ms-flex: 1 0 auto;
|
18
|
-
flex: 1 0 auto;
|
19
|
-
}
|