arask 1.2.4 → 1.2.6

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
  SHA256:
3
- metadata.gz: 124439fc5b51273732a02efb953350c77953bfd4c2fe120460d6bb74b8762f02
4
- data.tar.gz: a6c54e857d937e5d4e87a38b50c2c75a8beeb1d3e708e903047b15de2e6a74af
3
+ metadata.gz: 5741a13f8ff63776fec7bd2f2649d1278c31c0de6d5d336620c0afcfdfb5ddc8
4
+ data.tar.gz: af24a1563a8d90c8ad40cfc09faefce64f30613c53b9ef67ed997478470fc1a2
5
5
  SHA512:
6
- metadata.gz: f9b78ff561bb8e9dfcc1850f70f52550e045b6fee4a3fba4e2e687e9bce3d83f6e8032cd222dc07c45da5580fdad5f7a82065e8ce971628c8bea75003327c19f
7
- data.tar.gz: 1a075fc84d7cf53155725221774277822da02adfe06e418443fd6d825bdae0eb440bf41ee17c11504ab1325291b6c5bc7422d8ef5210e37cd3f4af2ff25c8435
6
+ metadata.gz: f2f45626df424803702bbfba1d53f2b390e8804e569e81092532ce573e332b2d6c95b3f0e6712f54427a8886cb950860568039238b9a1b3855ad9860ad1bc125
7
+ data.tar.gz: cacc24002657be607cbffd982bea58d3593d8c6e92e81cccb54cdd2a7b69a9940de5340fc7a8399597dedf2169a92c90f2c1e10a3792a8dd25693d90c64e8066
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Arask
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/arask.svg)](https://badge.fury.io/rb/arask)
3
- [![Build Status](https://travis-ci.org/Ebbe/arask.svg?branch=master)](https://travis-ci.org/Ebbe/arask)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/Ebbe/arask/badge.svg?branch=master)](https://coveralls.io/github/Ebbe/arask?branch=master)
5
5
 
6
6
  Automatic RAils taSKs (with minimal setup).
@@ -10,12 +10,15 @@ No need to setup anything outside of Rails. If Rails is running, so is Arask. If
10
10
  Use cron syntax or simply define the interval.
11
11
 
12
12
  ## Installation
13
+
13
14
  Add this line to your application's Gemfile:
15
+
14
16
  ```ruby
15
17
  gem 'arask'
16
18
  ```
17
19
 
18
20
  Execute:
21
+
19
22
  ```bash
20
23
  $ bundle install
21
24
  $ rails generate arask:install
@@ -25,9 +28,11 @@ $ rails db:migrate
25
28
  Setup your tasks in config/initializers/arask.rb. Initially it looks [like this](lib/arask/initialize.rb).
26
29
 
27
30
  ## Usage
31
+
28
32
  After installation, you can edit config/initializers/arask.rb with your tasks.
29
33
 
30
34
  ### Examples of jobs in the initializer
35
+
31
36
  ```ruby
32
37
  # Rake tasks with cron syntax
33
38
  arask.create task: 'send:logs', cron: '0 2 * * *' # At 02:00 every day
@@ -57,16 +62,20 @@ end
57
62
  ```
58
63
 
59
64
  ### About cron
65
+
60
66
  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
67
 
62
68
  Not supported is `@reboot`.
63
69
 
64
70
  ### About interval
71
+
65
72
  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
73
 
67
74
  ## 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:
75
+
76
+ - Have a "try again" feature. For instance `arask.create script: 'raise "I failed"', interval: :daily, fail_retry: 5.minutes, retry_at_most: 2`
77
+ - Be able to specify line and number that failed for an exception:
78
+
70
79
  ```ruby
71
80
  file,line,_ = caller.first.split(':')
72
81
  fileline = File.readlines(file)[line.to_i - 1].strip
@@ -75,16 +84,28 @@ fileline = File.readlines(file)[line.to_i - 1].strip
75
84
  ## Special environments
76
85
 
77
86
  ### Heroku
87
+
78
88
  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.
79
89
 
80
90
  ### Docker
91
+
81
92
  Nothing special to setup.
82
93
 
83
94
  ## Caveats
95
+
84
96
  If you reload a database dump, your jobs could be run again.
85
97
 
86
98
  ## Contributing
99
+
87
100
  Please use https://github.com/Ebbe/arask
88
101
 
102
+ ## Running tests
103
+
104
+ ```bash
105
+ $ bundle install
106
+ $ bundle exec rake test
107
+ ```
108
+
89
109
  ## License
110
+
90
111
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -8,9 +8,12 @@ module Arask
8
8
  calculate_new_execute_at
9
9
  begin
10
10
  if self.job.start_with?('Rake::Task')
11
- Rake.load_rakefile Rails.root.join( 'Rakefile' )
11
+ Rake.load_rakefile Rails.root.join('Rakefile') unless Rake::Task.task_defined?(self.job[12..-3])
12
+ eval(self.job + '.invoke')
13
+ eval(self.job + '.reenable')
14
+ else
15
+ eval(self.job)
12
16
  end
13
- eval(self.job)
14
17
  rescue Exception => e
15
18
  puts 'Arask: Job failed'
16
19
  p self
data/lib/arask/railtie.rb CHANGED
@@ -3,6 +3,6 @@ module Arask
3
3
  # Executes when the rails server is running
4
4
  server do
5
5
  Arask.init_jobs
6
- end
6
+ end if Rails::VERSION::MAJOR>=6
7
7
  end
8
8
  end
data/lib/arask/setup.rb CHANGED
@@ -16,7 +16,7 @@ module Arask
16
16
  return
17
17
  end
18
18
  unless task.nil?
19
- script = "Rake::Task['#{task}'].invoke"
19
+ script = "Rake::Task['#{task}']"
20
20
  end
21
21
  unless job.nil?
22
22
  script = "#{job}.perform_now"
data/lib/arask/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arask
2
- VERSION = '1.2.4'
2
+ VERSION = '1.2.6'
3
3
  end
data/lib/arask.rb CHANGED
@@ -9,10 +9,22 @@ module Arask
9
9
 
10
10
  def self.setup(force_run = false, &block)
11
11
  Arask.jobs_block = block
12
- # Make sure we only run setup now if we are testing.
13
- # Else we would run them at every cli execution.
14
- # railtie.rb inits the jobs when the server is ready
15
- Arask.init_jobs if force_run
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
26
+ end
27
+ end
16
28
  end
17
29
 
18
30
  def self.init_jobs
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arask
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esben Damgaard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-15 00:00:00.000000000 Z
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 3.2.3
93
+ rubygems_version: 3.3.26
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Automatic RAils taSKs (with minimal setup)