arask 0.1.1 → 0.1.2

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: ad49ba051c8cfa4ab0b8c3328bfd37bba6f284ae
4
- data.tar.gz: 5eeefd82e1a06a6a81fd063c3ef8fc38220aadde
3
+ metadata.gz: 5b51288be65c487cc7ef84a0911f9e2848e443ff
4
+ data.tar.gz: 329f36f92c8a6f877caeb401a036a609774c7f02
5
5
  SHA512:
6
- metadata.gz: e54575c4eb12a57d78ebdd7ea408b034869f96bf032dfb2865e984b280a681ff066262232aed03da147cc5768096d87c7511c32fed43adbc961da60b2ddef43e
7
- data.tar.gz: edbc56ec38e0373fb80085a63dce63ecb619ede93940c6ea6ae246adef394759ff3b4b8250c58df427488fd96db14359275d267da049480712b2f5112826c91f
6
+ metadata.gz: a89e7b82c415166c5b17752b3af454c2a08d1ebbf3d66af68d4ad6035262d2d06894680725b595aede27fb49fa31cf344c94a17b8601c23ebc21c14684832af4
7
+ data.tar.gz: bfe056cb38d460e6516539cf26093185d275edb52bfdcf9f61e7e316b324c4450f83f8b66f7997f6b5a3923a92e79bde7260457a61da9db04e283d970f8c9191
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Arask
2
- Automatic RAils taSKs.
2
+ Automatic RAils taSKs (with minimal setup).
3
3
 
4
- Beware that these tasks are only run when ActionController has successfully rendered an action. The interval specified is the _least_ time that will go since last run.
4
+ 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.
5
5
 
6
6
  ## Usage
7
7
  After installation, you can edit config/initializers/arask.rb with your tasks.
@@ -9,30 +9,33 @@ After installation, you can edit config/initializers/arask.rb with your tasks.
9
9
  ### Examples
10
10
  ```ruby
11
11
  arask.create script: 'puts "IM ALIVE!"', interval: :daily, run_first_time: true
12
- arask.create script: 'Attachment.process_new', interval: 5.hours
12
+ arask.create script: 'Attachment.process_new', interval: 5.hours if Rails.env.production?
13
13
  # Run rake task:
14
14
  arask.create task: 'my:awesome_task', interval: :hourly
15
15
  ```
16
16
 
17
17
  ## Installation
18
18
  Add this line to your application's Gemfile:
19
-
20
19
  ```ruby
21
20
  gem 'arask'
22
21
  ```
23
22
 
24
- And then execute:
25
- ```bash
26
- $ bundle
27
- ```
28
-
29
- Then install the initializer template and migration:
23
+ Execute:
30
24
  ```bash
25
+ $ bundle install
31
26
  $ rails generate arask:install
27
+ $ rails db:migrate
32
28
  ```
33
29
 
34
30
  Setup your tasks in config/initializers/arask.rb.
35
31
 
32
+ ## Todos
33
+ * Be able to setup error handling. For instance in initializer: `arask.on_fail email: 'gr34test_dev@example.com'`
34
+ * Have a "try again" feature. For instance `arask.create script: 'raise "I failed"', interval: :daily, fail_retry: 5.minutes, retry_at_most: 2`
35
+
36
+ ## Caveats
37
+ If you reload a database dump, your jobs could be run again.
38
+
36
39
  ## Contributing
37
40
  Please use https://github.com/Ebbe/arask
38
41
 
@@ -1,7 +1,7 @@
1
1
  Arask.setup do |arask|
2
2
  # Examples
3
3
  #arask.create script: 'puts "IM ALIVE!"', interval: :daily, run_first_time: true
4
- #arask.create script: 'Attachment.process_new', interval: 5.hours
4
+ #arask.create script: 'Attachment.process_new', interval: 5.hours if Rails.env.production?
5
5
  # Run rake task:
6
6
  #arask.create task: 'my:awesome_task', interval: :hourly
7
7
  end
data/lib/arask/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arask
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/arask.rb CHANGED
@@ -9,6 +9,17 @@ module Arask
9
9
  yield Arask
10
10
  begin
11
11
  AraskJob.all.where.not(id: @jobs_touched).delete_all
12
+ Arask.queue_self
13
+ rescue
14
+ end
15
+ end
16
+
17
+ def self.queue_self
18
+ begin
19
+ next_job_run = AraskJob.order(execute_at: :asc).first.try(:execute_at)
20
+ # At least check database for jobs every 5 minutes
21
+ next_job_run = 5.minutes.from_now if next_job_run.nil? or (next_job_run - DateTime.now)/60 > 5
22
+ RunJobs.set(wait_until: next_job_run).perform_later
12
23
  rescue
13
24
  end
14
25
  end
@@ -51,27 +62,15 @@ module Arask
51
62
  queue_as :default
52
63
 
53
64
  def perform
54
- AraskJob.transaction do
55
- AraskJob.where('execute_at < ?', DateTime.now).lock.each do |job|
56
- job.run
65
+ begin
66
+ AraskJob.transaction do
67
+ AraskJob.where('execute_at < ?', DateTime.now).lock.each do |job|
68
+ job.run
69
+ end
57
70
  end
71
+ rescue
58
72
  end
59
- next_job = AraskJob.order(execute_at: :desc).first
60
- if next_job
61
- Arask.time_cache = next_job.interval.seconds.from_now
62
- else
63
- Arask.time_cache = 5.minutes.from_now
64
- end
65
- end
66
- end
67
-
68
- ActionController::Base.instance_eval do
69
- after_action do
70
- Arask.time_cache ||= Time.now
71
- if Arask.time_cache <= Time.now
72
- Arask.time_cache = 5.minutes.from_now
73
- RunJobs.perform_later
74
- end
73
+ Arask.queue_self
75
74
  end
76
75
  end
77
76
  end
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: 0.1.1
4
+ version: 0.1.2
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-06-08 00:00:00.000000000 Z
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -26,7 +26,7 @@ dependencies:
26
26
  version: 5.1.0
27
27
  description: With minimal setup, be able to regularly run tasks.
28
28
  email:
29
- - esben@hvemder.dk
29
+ - ebbe@hvemder.dk
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
@@ -63,5 +63,5 @@ rubyforge_project:
63
63
  rubygems_version: 2.6.11
64
64
  signing_key:
65
65
  specification_version: 4
66
- summary: Automatic RAils taSKs
66
+ summary: Automatic RAils taSKs (with minimal setup)
67
67
  test_files: []