arask 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -10
- data/lib/arask/initialize.rb +1 -1
- data/lib/arask/version.rb +1 -1
- data/lib/arask.rb +18 -19
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b51288be65c487cc7ef84a0911f9e2848e443ff
|
4
|
+
data.tar.gz: 329f36f92c8a6f877caeb401a036a609774c7f02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
|
data/lib/arask/initialize.rb
CHANGED
@@ -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
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
|
-
|
55
|
-
AraskJob.
|
56
|
-
job
|
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
|
-
|
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.
|
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-
|
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
|
-
-
|
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: []
|