arask 1.2.0 → 1.2.5

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
- SHA1:
3
- metadata.gz: e2055444d486251702ec8f09cc6944742f4ef45e
4
- data.tar.gz: 3215c191aab13ce67fec68d09ec02962314f528b
2
+ SHA256:
3
+ metadata.gz: 277e0095ea412d5b05a792f0a2210b987165b9e18c292770f5655b75ffa5dc38
4
+ data.tar.gz: 3afcc9cc2d53b69aeb4831d30b26afa1931289bfdd58fdf3c75dc3199d9a55ac
5
5
  SHA512:
6
- metadata.gz: ba226a137d88675b7375f5bc59cdd780437a5f9bd218c7523ec8ad149823d03511b96a358acb3ca8b2d2a26d9b36a3577bb134925b03ee0f9a8c75721cf53cc0
7
- data.tar.gz: af1ab2f4a7933407c0361e4f14fc09a8c00f974db29859a3532fabe374a25f28db8cfca5fc7c252af539f17f28f632c51b77ea3c1cd5bc4709aa88eae6fce408
6
+ metadata.gz: df3e1a1400bd5e3584380219422f586551af432e13cdee39544640295a9bd7635c594957c45d8af3bf080ac0f09010e28928e8b79aebbfbe1a8ebbdd1aa1d4e2
7
+ data.tar.gz: 1ecd42c9bf9448c4fccd78f335cc9b84fd26201ac6727894849de3ca0318a6f5194199f5c193c865ca1ba1458fc5ccab78d0b90626db9aea72f9738a6f097b9d
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Arask
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/arask.svg)](https://badge.fury.io/rb/arask)
3
4
  [![Build Status](https://travis-ci.org/Ebbe/arask.svg?branch=master)](https://travis-ci.org/Ebbe/arask)
4
5
  [![Coverage Status](https://coveralls.io/repos/github/Ebbe/arask/badge.svg?branch=master)](https://coveralls.io/github/Ebbe/arask?branch=master)
@@ -10,12 +11,15 @@ No need to setup anything outside of Rails. If Rails is running, so is Arask. If
10
11
  Use cron syntax or simply define the interval.
11
12
 
12
13
  ## Installation
14
+
13
15
  Add this line to your application's Gemfile:
16
+
14
17
  ```ruby
15
18
  gem 'arask'
16
19
  ```
17
20
 
18
21
  Execute:
22
+
19
23
  ```bash
20
24
  $ bundle install
21
25
  $ rails generate arask:install
@@ -25,9 +29,11 @@ $ rails db:migrate
25
29
  Setup your tasks in config/initializers/arask.rb. Initially it looks [like this](lib/arask/initialize.rb).
26
30
 
27
31
  ## Usage
32
+
28
33
  After installation, you can edit config/initializers/arask.rb with your tasks.
29
34
 
30
35
  ### Examples of jobs in the initializer
36
+
31
37
  ```ruby
32
38
  # Rake tasks with cron syntax
33
39
  arask.create task: 'send:logs', cron: '0 2 * * *' # At 02:00 every day
@@ -52,34 +58,55 @@ arask.on_exception email: 'errors@example.com'
52
58
 
53
59
  # Run code on exceptions
54
60
  arask.on_exception do |exception, arask_job|
55
- Honeybadger.notify(exception)
61
+ MyExceptionHandler.new(exception)
56
62
  end
57
63
  ```
58
64
 
59
65
  ### About cron
66
+
60
67
  Arask uses [fugit](https://github.com/floraison/fugit) to parse cron and get next execution time. It follows normal cron syntax. You can test your cron at https://crontab.guru/.
61
68
 
62
69
  Not supported is `@reboot`.
63
70
 
64
71
  ### About interval
72
+
65
73
  The interval starts when the task has started running. If a task with the interval `:hourly` is run at 08:37PM, then it will run the next time at 09:37PM.
66
74
 
67
75
  ## Todos
68
- * Have a "try again" feature. For instance `arask.create script: 'raise "I failed"', interval: :daily, fail_retry: 5.minutes, retry_at_most: 2`
69
- * Be able to specify line and number that failed for an exception:
76
+
77
+ - Have a "try again" feature. For instance `arask.create script: 'raise "I failed"', interval: :daily, fail_retry: 5.minutes, retry_at_most: 2`
78
+ - Be able to specify line and number that failed for an exception:
79
+
70
80
  ```ruby
71
81
  file,line,_ = caller.first.split(':')
72
82
  fileline = File.readlines(file)[line.to_i - 1].strip
73
83
  ```
74
84
 
75
- ## Setup for Heroku
76
- None. But if you use a hobby dyno and it falls to sleep, so will Arask. As soon as the dyno wakes up, Arask will run any pending jobs.
85
+ ## Special environments
86
+
87
+ ### Heroku
88
+
89
+ Nothing special to setup. But if you use a hobby dyno and it falls to sleep, so will Arask. As soon as the dyno wakes up, Arask will run any pending jobs.
90
+
91
+ ### Docker
92
+
93
+ Nothing special to setup.
77
94
 
78
95
  ## Caveats
96
+
79
97
  If you reload a database dump, your jobs could be run again.
80
98
 
81
99
  ## Contributing
100
+
82
101
  Please use https://github.com/Ebbe/arask
83
102
 
103
+ ## Running tests
104
+
105
+ ```bash
106
+ $ bundle install
107
+ $ bundle exec rake test
108
+ ```
109
+
84
110
  ## License
111
+
85
112
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/lib/arask.rb CHANGED
@@ -5,29 +5,44 @@ require "arask/setup"
5
5
  require 'fugit' # To parse cron
6
6
 
7
7
  module Arask
8
- class << self; attr_accessor :jobs_touched, :exception_email, :exception_email_from, :exception_block; end
8
+ class << self; attr_accessor :jobs_touched, :exception_email, :exception_email_from, :exception_block, :jobs_block; end
9
9
 
10
- def self.setup
11
- # Make sure we only run setup if Rails is actually run as a server or testing.
12
- return unless defined?(Rails::Server) or Rails.env.test?
13
- # If we don't wait and rails is setup to use another language, ActiveJob
14
- # saves what is now (usually :en) and reloads that when trying to run the
15
- # job. Renderering an I18n error of unsupported language.
16
- ActiveSupport.on_load :after_initialize, yield: true do
17
- Arask.jobs_touched = []
18
- yield Setup
19
- begin
20
- AraskJob.all.where.not(id: Arask.jobs_touched).delete_all
21
- Arask.queue_self
22
- rescue
10
+ def self.setup(force_run = false, &block)
11
+ Arask.jobs_block = block
12
+ if Rails::VERSION::MAJOR>=6
13
+ # Make sure we only run setup now if we are testing.
14
+ # Else we would run them at every cli execution.
15
+ # railtie.rb inits the jobs when the server is ready
16
+ Arask.init_jobs if force_run
17
+ else # Rails is less than 6
18
+
19
+ # Make sure we only run setup if Rails is actually run as a server or testing.
20
+ return unless defined?(Rails::Server) or force_run
21
+ # If we don't wait and rails is setup to use another language, ActiveJob
22
+ # saves what is now (usually :en) and reloads that when trying to run the
23
+ # job. Renderering an I18n error of unsupported language.
24
+ ActiveSupport.on_load :after_initialize, yield: true do
25
+ Arask.init_jobs
23
26
  end
24
27
  end
25
28
  end
26
29
 
30
+ def self.init_jobs
31
+ Arask.jobs_touched = []
32
+ Arask.jobs_block.call(Setup)
33
+ Arask.jobs_block = nil
34
+ begin
35
+ AraskJob.all.where.not(id: Arask.jobs_touched).delete_all
36
+ Arask.jobs_touched = nil
37
+ Arask.queue_self
38
+ rescue
39
+ end
40
+ end
41
+
27
42
  def self.queue_self
28
43
  begin
29
44
  next_job_run = AraskJob.order(execute_at: :asc).first.try(:execute_at)
30
- # At least check database for jobs every 5 minutes
45
+ # At least check database for jobs every day
31
46
  next_job_run = 1.day.from_now if next_job_run.nil? or (next_job_run - DateTime.now)/60/60 > 24
32
47
  RunJobs.set(wait_until: next_job_run).perform_later
33
48
  rescue
@@ -24,6 +24,6 @@ Arask.setup do |arask|
24
24
 
25
25
  # Run code on exceptions
26
26
  #arask.on_exception do |exception, arask_job|
27
- # Honeybadger.notify(exception)
27
+ # MyExceptionHandler.new(exception)
28
28
  #end
29
29
  end
data/lib/arask/railtie.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  module Arask
2
2
  class Railtie < ::Rails::Railtie
3
+ # Executes when the rails server is running
4
+ server do
5
+ Arask.init_jobs
6
+ end if Rails::VERSION::MAJOR>=6
3
7
  end
4
8
  end
data/lib/arask/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arask
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.5'
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arask
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esben Damgaard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-03 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.1'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.1'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fugit
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -90,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.6.11
93
+ rubygems_version: 3.2.15
95
94
  signing_key:
96
95
  specification_version: 4
97
96
  summary: Automatic RAils taSKs (with minimal setup)