Compare commits

...

30 Commits
v2.0.0 ... main

Author SHA1 Message Date
Dzmitry Plashchynski
6c7ff2f7b1 Bump 2.1.0 2024-12-18 14:58:42 +03:00
Dzmitry Plashchynski
2e663c2104 Merge pull request #127 from janko/rails-7.2
Add Rails 7.2 support
2024-08-19 21:57:22 +09:00
Janko Marohnić
ab4e1e808d Call clear_active_connections! on the connection handler
Active Record 7.2 removed the deprecated
`ActiveRecord::Base.clear_active_connections!` delegate method.
2024-08-19 14:49:59 +02:00
Janko Marohnić
9a8e8049f9 Add Propshaft for tests
Otherwise Crono doesn't have an asset pipeline, so the engine initializer
raises an error.
2024-08-19 14:49:25 +02:00
Dzmitry Plashchynski
6bf1ec9cfd Merge pull request #119 from petergoldstein/feature/add_ruby_3_2_to_ci
Adds Ruby 3.2 to the CI matrix
2024-05-23 23:10:03 +03:00
Dzmitry Plashchynski
d3dc79e4f1 Merge pull request #124 from cisolarix/patch-1
fix: typo
2024-05-23 01:58:42 +03:00
Dzmitry Plashchynski
e0f41858e0 Merge pull request #125 from simi/memory
Remove :memory file and fix in-memory SQLite setup.
2024-05-23 01:57:42 +03:00
Josef Šimánek
e277fd9fb7 Remove :memory file and fix in-memory SQLite setup.
- :memory file makes it problematic on Windows
2024-05-23 00:34:15 +02:00
Yanming Deng
d4cc325685 fix: typo 2024-04-15 21:28:23 +08:00
Chrıs Seelus
0bfdc6996b Merge pull request #123 from janko/allow-propshaft
Remove Sprockets hard dependency, allow Propshaft
2023-12-19 19:43:54 +01:00
Janko Marohnić
7dffc5c77b Remove Sprockets hard dependency, allow Propshaft 2023-12-15 17:44:15 +01:00
Peter Goldstein
bfbb8733cd Adds Ruby 3.2 to the CI matrix 2023-01-21 14:47:31 -05:00
Dzmitry Plashchynski
4294bad43a Update Gemfile.lock 2022-09-03 19:22:59 +03:00
Dzmitry Plashchynski
0702e20add Bump 2.0.1 2022-09-03 15:27:02 +03:00
Dzmitry Plashchynski
db8c29afbe Merge pull request #109 from itbeaver/fix_job_args
Fixes arguments for jobs
2022-09-03 15:22:26 +03:00
Aleksandr Bobrov
43e411cf0f Fix args 2022-09-03 00:26:10 +04:00
Dzmitry Plashchynski
e43ad4d409 Merge pull request #108 from plashchynski/dependabot/bundler/activerecord-7.0.3.1
Bump activerecord from 7.0.3 to 7.0.3.1
2022-07-24 22:52:25 +03:00
Dzmitry Plashchynski
c5c58b559f Write PID in the daemon mode 2022-07-24 22:50:05 +03:00
Dzmitry Plashchynski
81d1e3496f remove duplicated file 2022-07-24 22:44:45 +03:00
Dzmitry Plashchynski
ddbfa4c42e Fix specs 2022-07-24 22:38:08 +03:00
Dzmitry Plashchynski
e03d9b4ba6 Remove crono_test.sqlite from git cache 2022-07-24 22:37:50 +03:00
dependabot[bot]
811ab31978 Bump activerecord from 7.0.3 to 7.0.3.1
Bumps [activerecord](https://github.com/rails/rails) from 7.0.3 to 7.0.3.1.
- [Release notes](https://github.com/rails/rails/releases)
- [Changelog](https://github.com/rails/rails/blob/v7.0.3.1/activerecord/CHANGELOG.md)
- [Commits](https://github.com/rails/rails/compare/v7.0.3...v7.0.3.1)

---
updated-dependencies:
- dependency-name: activerecord
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-15 11:38:13 +00:00
Dzmitry Plashchynski
cb5064852a Merge pull request #107 from mediafinger/add-github-actions-for-specs
Add GitHub actions for specs
2022-07-15 14:37:21 +03:00
Andreas Finger
a421a6207b ci: Add GitHub Action to run specs 2022-07-11 10:43:02 +02:00
Andreas Finger
4abc999583 doc: List compatible Ruby versions in the README 2022-07-11 10:41:20 +02:00
Dzmitry Plashchynski
0e1dec2956 Merge pull request #106 from plashchynski/dependabot/bundler/rails-html-sanitizer-1.4.3
Bump rails-html-sanitizer from 1.4.2 to 1.4.3
2022-07-08 13:05:37 +03:00
dependabot[bot]
3a17938571 Bump rails-html-sanitizer from 1.4.2 to 1.4.3
Bumps [rails-html-sanitizer](https://github.com/rails/rails-html-sanitizer) from 1.4.2 to 1.4.3.
- [Release notes](https://github.com/rails/rails-html-sanitizer/releases)
- [Changelog](https://github.com/rails/rails-html-sanitizer/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rails/rails-html-sanitizer/compare/v1.4.2...v1.4.3)

---
updated-dependencies:
- dependency-name: rails-html-sanitizer
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-06 12:23:15 +00:00
Dzmitry Plashchynski
5391930954 Merge branch 'main' of https://github.com/plashchynski/crono 2022-06-16 11:08:28 +02:00
Dzmitry Plashchynski
5c16c8c6dd Do not pass empty arguments to the worker. Closes #95 2022-06-16 11:08:22 +02:00
Dzmitry Plashchynski
b1cc71e9a4 Update README.md 2022-05-30 00:25:46 +03:00
19 changed files with 300 additions and 286 deletions

36
.github/workflows/rspec.yml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: "RSpec"
on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '00 12 * * *' # daily at 12:00
jobs:
specs:
name: specs
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ruby: ['2.7', '3.0', '3.1', '3.2'] # Due to https://github.com/actions/runner/issues/849, we have to use quotes
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Ruby and install gems
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
cache-version: 1 # change this value when you have to empty the cache manually
- name: Run specs
run: |
bundle exec rspec spec/

3
.gitignore vendored
View File

@@ -9,3 +9,6 @@
log/*.log
.byebug_history
spec/internal
# macOS stuff
.DS_Store

View File

@@ -1,3 +1,11 @@
2.1.0
-----------
- Add Rails 7.2 support (thanks to @janko)
2.0.1
-----------
- Fix a job argument error
2.0.0
-----------
- Converted this gem to a proper Rails engine

View File

@@ -1,208 +1,243 @@
PATH
remote: .
specs:
crono (1.1.2)
crono (2.1.0)
rails (>= 5.2.8)
sprockets-rails
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.3)
actionpack (= 7.0.3)
activesupport (= 7.0.3)
actioncable (7.2.0)
actionpack (= 7.2.0)
activesupport (= 7.2.0)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.3)
actionpack (= 7.0.3)
activejob (= 7.0.3)
activerecord (= 7.0.3)
activestorage (= 7.0.3)
activesupport (= 7.0.3)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.3)
actionpack (= 7.0.3)
actionview (= 7.0.3)
activejob (= 7.0.3)
activesupport (= 7.0.3)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.3)
actionview (= 7.0.3)
activesupport (= 7.0.3)
rack (~> 2.0, >= 2.2.0)
zeitwerk (~> 2.6)
actionmailbox (7.2.0)
actionpack (= 7.2.0)
activejob (= 7.2.0)
activerecord (= 7.2.0)
activestorage (= 7.2.0)
activesupport (= 7.2.0)
mail (>= 2.8.0)
actionmailer (7.2.0)
actionpack (= 7.2.0)
actionview (= 7.2.0)
activejob (= 7.2.0)
activesupport (= 7.2.0)
mail (>= 2.8.0)
rails-dom-testing (~> 2.2)
actionpack (7.2.0)
actionview (= 7.2.0)
activesupport (= 7.2.0)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4, < 3.2)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.3)
actionpack (= 7.0.3)
activerecord (= 7.0.3)
activestorage (= 7.0.3)
activesupport (= 7.0.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
useragent (~> 0.16)
actiontext (7.2.0)
actionpack (= 7.2.0)
activerecord (= 7.2.0)
activestorage (= 7.2.0)
activesupport (= 7.2.0)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.3)
activesupport (= 7.0.3)
actionview (7.2.0)
activesupport (= 7.2.0)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.3)
activesupport (= 7.0.3)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (7.2.0)
activesupport (= 7.2.0)
globalid (>= 0.3.6)
activemodel (7.0.3)
activesupport (= 7.0.3)
activerecord (7.0.3)
activemodel (= 7.0.3)
activesupport (= 7.0.3)
activestorage (7.0.3)
actionpack (= 7.0.3)
activejob (= 7.0.3)
activerecord (= 7.0.3)
activesupport (= 7.0.3)
activemodel (7.2.0)
activesupport (= 7.2.0)
activerecord (7.2.0)
activemodel (= 7.2.0)
activesupport (= 7.2.0)
timeout (>= 0.4.0)
activestorage (7.2.0)
actionpack (= 7.2.0)
activejob (= 7.2.0)
activerecord (= 7.2.0)
activesupport (= 7.2.0)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
activesupport (7.2.0)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
tzinfo (~> 2.0)
builder (3.2.4)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
base64 (0.2.0)
bigdecimal (3.1.8)
builder (3.3.0)
byebug (11.1.3)
combustion (1.3.6)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
thor (>= 0.14.6)
concurrent-ruby (1.1.10)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
daemons (1.4.1)
diff-lcs (1.5.0)
digest (3.1.0)
erubi (1.10.0)
globalid (1.0.0)
activesupport (>= 5.0)
date (3.3.4)
diff-lcs (1.5.1)
drb (2.2.1)
erubi (1.13.0)
globalid (1.2.1)
activesupport (>= 6.1)
haml (5.2.2)
temple (>= 0.8.0)
tilt
i18n (1.10.0)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
loofah (2.18.0)
io-console (0.7.2)
irb (1.14.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
logger (1.6.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
nokogiri (>= 1.12.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.2)
minitest (5.15.0)
net-imap
net-pop
net-smtp
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.25.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
net-imap (0.2.3)
digest
net-imap (0.4.14)
date
net-protocol
strscan
net-pop (0.1.1)
digest
net-pop (0.1.2)
net-protocol (0.2.2)
timeout
net-smtp (0.5.0)
net-protocol
timeout
net-protocol (0.1.3)
timeout
net-smtp (0.3.1)
digest
net-protocol
timeout
nio4r (2.5.8)
nokogiri (1.13.6-arm64-darwin)
nio4r (2.7.3)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
racc (1.6.0)
rack (2.2.3.1)
nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
propshaft (0.9.1)
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
rack
railties (>= 7.0.0)
psych (5.1.2)
stringio
racc (1.8.1)
rack (2.2.9)
rack-protection (2.2.0)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (7.0.3)
actioncable (= 7.0.3)
actionmailbox (= 7.0.3)
actionmailer (= 7.0.3)
actionpack (= 7.0.3)
actiontext (= 7.0.3)
actionview (= 7.0.3)
activejob (= 7.0.3)
activemodel (= 7.0.3)
activerecord (= 7.0.3)
activestorage (= 7.0.3)
activesupport (= 7.0.3)
rack-session (1.0.2)
rack (< 3)
rack-test (2.1.0)
rack (>= 1.3)
rackup (1.0.0)
rack (< 3)
webrick
rails (7.2.0)
actioncable (= 7.2.0)
actionmailbox (= 7.2.0)
actionmailer (= 7.2.0)
actionpack (= 7.2.0)
actiontext (= 7.2.0)
actionview (= 7.2.0)
activejob (= 7.2.0)
activemodel (= 7.2.0)
activerecord (= 7.2.0)
activestorage (= 7.2.0)
activesupport (= 7.2.0)
bundler (>= 1.15.0)
railties (= 7.0.3)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
railties (= 7.2.0)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
railties (7.0.3)
actionpack (= 7.0.3)
activesupport (= 7.0.3)
method_source
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.2.0)
actionpack (= 7.2.0)
activesupport (= 7.2.0)
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rake (13.2.1)
rdoc (6.7.0)
psych (>= 4.0.0)
reline (0.5.9)
io-console (~> 0.5)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-rails (5.1.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.11.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.4)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
ruby2_keywords (0.0.5)
securerandom (0.3.1)
sinatra (2.2.0)
mustermann (~> 1.0)
rack (~> 2.2)
rack-protection (= 2.2.0)
tilt (~> 2.0)
sprockets (4.0.3)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
strscan (3.0.3)
sqlite3 (2.0.4-arm64-darwin)
sqlite3 (2.0.4-x86_64-darwin)
sqlite3 (2.0.4-x86_64-linux-gnu)
stringio (3.1.1)
temple (0.8.2)
thor (1.2.1)
thor (1.3.1)
tilt (2.0.10)
timecop (0.9.5)
timeout (0.3.0)
tzinfo (2.0.4)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
websocket-driver (0.7.5)
useragent (0.16.10)
webrick (1.8.1)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.5.4)
zeitwerk (2.6.17)
PLATFORMS
arm64-darwin-21
arm64-darwin-23
arm64-darwin-24
x86_64-darwin-21
x86_64-darwin-22
x86_64-linux
DEPENDENCIES
bundler (>= 2)
@@ -211,6 +246,7 @@ DEPENDENCIES
crono!
daemons
haml
propshaft
rack-test
rake (>= 10.0)
rspec (>= 3.0)
@@ -220,4 +256,4 @@ DEPENDENCIES
timecop (>= 0.7)
BUNDLED WITH
2.3.14
2.4.4

View File

@@ -8,7 +8,7 @@ Crono is a time-based background job scheduler daemon (just like Cron) for Ruby
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.
![Web UI](https://github.com/plashchynski/crono/raw/master/examples/crono_web_ui.png)
![Web UI](https://github.com/plashchynski/crono/raw/main/examples/crono_web_ui.png)
## Installation
@@ -31,12 +31,16 @@ Run the migration:
Now you are ready to move forward to create a job and schedule it.
### Compatibility
* **Crono v1.1.2** and older are compatible with Ruby 2.7.x and older
* **Crono v2.0.0** and newer are compatible with Ruby 2.7.x and _newer_
## Usage
### The basic usage
You can specigy a simple job by editing ```config/cronotab.rb```:
You can specify a simple job by editing ```config/cronotab.rb```:
```ruby
# config/cronotab.rb
@@ -162,7 +166,7 @@ Usage: crono [options] [start|stop|restart|run]
-e, --environment ENV Application environment (Default: development)
```
#### Run as a daemon
### Run as a daemon
To run Crono as a daemon, please add to your Gemfile:
@@ -190,7 +194,7 @@ Rails.application.routes.draw do
Access management and other questions described in the [wiki](https://github.com/plashchynski/crono/wiki/Web-UI).
#### Known issues
## Known issues
For Rails 5, in case of the errors:
```
@@ -203,6 +207,20 @@ See the related issue [#52](https://github.com/plashchynski/crono/issues/52)
Use the `capistrano-crono` gem ([github](https://github.com/plashchynski/capistrano-crono/)).
## Development
### Running tests
To run the tests, you need to have a database. You can use the default SQLite database:
bundle exec rspec
### Publishing
To publish a new version, you need to update the version number in `lib/crono/version.rb` and then run:
bundle exec rake release
## Support
@@ -211,4 +229,4 @@ Feel free to create an [issues](https://github.com/plashchynski/crono/issues)
## License
Please see [LICENSE](https://github.com/plashchynski/crono/blob/master/LICENSE) for licensing details.
Please see [LICENSE](LICENSE) for licensing details.

View File

@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency 'rails', '>= 5.2.8'
s.add_dependency 'sprockets-rails'
s.add_development_dependency 'rake', '>= 13.0.1'
s.add_development_dependency 'bundler', '>= 2'
s.add_development_dependency 'rspec', '>= 3.10'
@@ -30,4 +29,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'haml'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'daemons'
s.add_development_dependency 'propshaft'
end

View File

@@ -3,7 +3,6 @@ module Crono
end
require 'rails'
require 'sprockets/railtie'
require 'active_support/all'
require 'crono/version'
require 'crono/engine'

View File

@@ -24,7 +24,7 @@ module Crono
setup_log
write_pid unless config.daemonize
write_pid if config.daemonize
load_rails
Cronotab.process(File.expand_path(config.cronotab))
print_banner

View File

@@ -3,7 +3,11 @@ module Crono
isolate_namespace Crono
initializer 'crono.assets.precompile' do |app|
app.config.assets.precompile += %w( crono/application.css crono/materialize.min.css )
if app.config.respond_to?(:assets)
app.config.assets.precompile += %w( crono/application.css crono/materialize.min.css )
else
fail "Crono requires either Propshaft or Sprockets to be installed."
end
end
config.generators do |g|

View File

@@ -9,10 +9,10 @@ module Crono
attr_accessor :performer, :period, :job_args, :last_performed_at, :job_options,
:next_performed_at, :job_log, :job_logger, :healthy, :execution_interval
def initialize(performer, period, job_args, job_options = nil)
def initialize(performer, period, job_args = nil, job_options = nil)
self.execution_interval = 0.minutes
self.performer, self.period = performer, period
self.job_args = JSON.generate(job_args)
self.job_args = JSON.generate(job_args) if job_args.present?
self.job_log = StringIO.new
self.job_logger = Logger.new(job_log)
self.job_options = job_options || {}
@@ -47,7 +47,7 @@ module Crono
@semaphore.synchronize do
update_model
clear_job_log
ActiveRecord::Base.clear_active_connections!
ActiveRecord::Base.connection_handler.clear_active_connections!
end
end

View File

@@ -1,14 +1,15 @@
module Crono
# Crono::PerformerProxy is a proxy used in cronotab.rb semantic
class PerformerProxy
def initialize(performer, scheduler, job_args)
def initialize(performer, scheduler, job_args = nil, job_options = nil)
@performer = performer
@scheduler = scheduler
@job_args = job_args
@job_options = job_options
end
def every(period, **options)
@job = Job.new(@performer, Period.new(period, **options), @job_args, @options)
@job = Job.new(@performer, Period.new(period, **options), @job_args, @job_options)
@scheduler.add_job(@job)
self
end
@@ -19,12 +20,12 @@ module Crono
end
def with_options(options)
@options = options
@job_options = options
self
end
end
def self.perform(performer, *job_args)
PerformerProxy.new(performer, Crono.scheduler, job_args)
PerformerProxy.new(performer, Crono.scheduler, *job_args)
end
end

View File

@@ -1,3 +1,3 @@
module Crono
VERSION = '2.0.0'
VERSION = '2.1.0'
end

View File

@@ -11,7 +11,7 @@ describe Crono::CLI do
expect(cli).to receive(:start_working_loop)
expect(cli).to receive(:parse_options)
expect(cli).to receive(:parse_command)
expect(cli).to receive(:write_pid)
expect(cli).not_to receive(:write_pid)
expect(Crono::Cronotab).to receive(:process)
cli.run
end
@@ -25,7 +25,8 @@ describe Crono::CLI do
expect(cli).to receive(:start_working_loop_in_daemon)
expect(cli).to receive(:parse_options)
expect(cli).to receive(:parse_command)
expect(cli).not_to receive(:write_pid)
expect(cli).to receive(:setup_log)
expect(cli).to receive(:write_pid)
expect(Crono::Cronotab).to receive(:process)
cli.run
end

Binary file not shown.

Binary file not shown.

View File

@@ -1,23 +1,30 @@
require 'spec_helper'
class TestJob
def perform(args)
def perform(*args)
puts 'Test!'
end
end
class TestFailingJob
def perform(args)
def perform(*args)
raise 'Some error'
end
end
class TestNoArgsJob
def perform
puts 'Test!'
end
end
describe Crono::Job do
let(:period) { Crono::Period.new(2.day, at: '15:00') }
let(:job_args) {[{some: 'data'}]}
let(:job) { Crono::Job.new(TestJob, period, []) }
let(:job_with_args) { Crono::Job.new(TestJob, period, job_args) }
let(:failing_job) { Crono::Job.new(TestFailingJob, period, []) }
let(:not_args_job) { Crono::Job.new(TestJob, period) }
it 'should contain performer and period' do
expect(job.performer).to be TestJob
@@ -70,6 +77,10 @@ describe Crono::Job do
test_preform_job_twice
end
it 'should execute twice without args' do
test_preform_job_twice not_args_job
end
it 'should execute twice without initialize execution_interval' do
test_preform_job_twice
end
@@ -88,10 +99,10 @@ describe Crono::Job do
expect(thread).to be_stop
end
def test_preform_job_twice
expect(job).to receive(:perform_job).twice
job.perform.join
thread = job.perform.join
def test_preform_job_twice(jon_instance = job)
expect(jon_instance).to receive(:perform_job).twice
jon_instance.perform.join
thread = jon_instance.perform.join
expect(thread).to be_stop
end
end

View File

@@ -26,13 +26,19 @@ describe Crono::PerformerProxy do
end
it 'should add job with args to schedule' do
expect(Crono::Job).to receive(:new).with(TestJob, kind_of(Crono::Period), [:some, {some: 'data'}], nil)
expect(Crono::Job).to receive(:new).with(TestJob, kind_of(Crono::Period), :some, { some: 'data' })
allow(Crono.scheduler).to receive(:add_job)
Crono.perform(TestJob, :some, {some: 'data'}).every(2.days, at: '15:30')
Crono.perform(TestJob, :some, { some: 'data' }).every(2.days, at: '15:30')
end
it 'should add job without args to schedule' do
expect(Crono::Job).to receive(:new).with(TestJob, kind_of(Crono::Period), nil, nil)
allow(Crono.scheduler).to receive(:add_job)
Crono.perform(TestJob).every(2.days, at: '15:30')
end
it 'should add job with options to schedule' do
expect(Crono::Job).to receive(:new).with(TestJob, kind_of(Crono::Period), [], {some_option: true})
expect(Crono::Job).to receive(:new).with(TestJob, kind_of(Crono::Period), nil, { some_option: true })
allow(Crono.scheduler).to receive(:add_job)
Crono.perform(TestJob).with_options(some_option: true).every(2.days, at: '15:30')
end

View File

@@ -23,7 +23,7 @@ ActiveRecord::Base.logger = Logger.new($stdout)
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: ':memory'
database: ':memory:'
)
ActiveRecord::Schema.define do
require_relative '../lib/generators/crono/install/templates/migrations/create_crono_jobs.rb'

View File

@@ -1,109 +0,0 @@
require 'spec_helper'
require 'crono/cli'
describe Crono::CLI do
let(:cli) { Crono::CLI.instance }
describe '#run' do
it 'should initialize rails with #load_rails and start working loop' do
expect(cli).to receive(:load_rails)
expect(cli).to receive(:have_jobs?).and_return(true)
expect(cli).to receive(:start_working_loop)
expect(cli).to receive(:parse_options)
expect(cli).to receive(:parse_command)
expect(cli).to receive(:write_pid)
expect(Crono::Cronotab).to receive(:process)
cli.run
end
context 'should run as daemon' do
before { cli.config.daemonize = true }
it 'should initialize rails with #load_rails and start working loop' do
expect(cli).to receive(:load_rails)
expect(cli).to receive(:have_jobs?).and_return(true)
expect(cli).to receive(:start_working_loop_in_daemon)
expect(cli).to receive(:parse_options)
expect(cli).to receive(:parse_command)
expect(cli).not_to receive(:write_pid)
expect(Crono::Cronotab).to receive(:process)
cli.run
end
end
end
describe '#parse_options' do
it 'should set cronotab' do
cli.send(:parse_options, ['--cronotab', '/tmp/cronotab.rb'])
expect(cli.config.cronotab).to be_eql '/tmp/cronotab.rb'
end
it 'should set logfile' do
cli.send(:parse_options, ['--logfile', 'log/crono.log'])
expect(cli.config.logfile).to be_eql 'log/crono.log'
end
it 'should set pidfile' do
cli.send(:parse_options, ['--pidfile', 'tmp/pids/crono.0.log'])
expect(cli.config.pidfile).to be_eql 'tmp/pids/crono.0.log'
end
it 'should set piddir' do
cli.send(:parse_options, ['--piddir', 'tmp/pids'])
expect(cli.config.piddir).to be_eql 'tmp/pids'
end
it 'should set process_name' do
cli.send(:parse_options, ['--process_name', 'crono0'])
expect(cli.config.process_name).to be_eql 'crono0'
end
it 'should set monitor' do
cli.send(:parse_options, ['--monitor'])
expect(cli.config.monitor).to be true
end
it 'should set environment' do
cli.send(:parse_options, ['--environment', 'production'])
expect(cli.config.environment).to be_eql('production')
end
end
describe '#parse_command' do
it 'should set daemonize on start' do
cli.send(:parse_command, ['start'])
expect(cli.config.daemonize).to be true
end
it 'should set daemonize on stop' do
cli.send(:parse_command, ['stop'])
expect(cli.config.daemonize).to be true
end
it 'should set daemonize on restart' do
cli.send(:parse_command, ['restart'])
expect(cli.config.daemonize).to be true
end
it 'should set daemonize on run' do
cli.send(:parse_command, ['run'])
expect(cli.config.daemonize).to be true
end
it 'should set daemonize on zap' do
cli.send(:parse_command, ['zap'])
expect(cli.config.daemonize).to be true
end
it 'should set daemonize on reload' do
cli.send(:parse_command, ['reload'])
expect(cli.config.daemonize).to be true
end
it 'should set daemonize on status' do
cli.send(:parse_command, ['status'])
expect(cli.config.daemonize).to be true
end
end
end