active_waiter 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -3
- data/app/controllers/active_waiter/jobs_controller.rb +1 -1
- data/lib/active_waiter/enumerable_job.rb +29 -0
- data/lib/active_waiter/job.rb +3 -1
- data/lib/active_waiter/version.rb +1 -1
- data/lib/active_waiter.rb +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2208fadf74c295220f10cac3714b6f8fa64d8c04
|
4
|
+
data.tar.gz: 1cd270203efe90bc7d94083a608f6933b29bb769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d783491504ea06ddddb4229dbb322c053f1a3c6d4753bbb1e6f01040f2e34d417e97102ae3e5b1c85cc8222fe446e9653898873c95b4e939fcdd3f9d788b8e91
|
7
|
+
data.tar.gz: aaac2b8016a772a4074b6ef5a2d028ad28ed88e8c267dc6f86fe6c38dc4ca894026750db4f4c54e8197cb37ad28f4e61d441c93d16f8f9d56863d198e63996ee
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ But how do you get that PDF into the hands of your users now? Email? Push notifi
|
|
29
29
|
|
30
30
|
## Solution
|
31
31
|
|
32
|
-
Let `ActiveWaiter` enqueue that job instead and redirect to
|
32
|
+
Let `ActiveWaiter` enqueue that job instead and redirect to its progress tracking page.
|
33
33
|
|
34
34
|
``` ruby
|
35
35
|
def index
|
@@ -103,7 +103,51 @@ ActiveWaiter.configure do |config|
|
|
103
103
|
end
|
104
104
|
```
|
105
105
|
|
106
|
-
Next, prefix any routes used in your application's layout with `main_app.`, e.g. `main_app.sign_in_path`.
|
106
|
+
Next, prefix any routes used in your application's layout with `main_app.`, e.g. `main_app.sign_in_path`.
|
107
107
|
|
108
|
-
This is required because `ActiveWaiter` is a Rails Engine mounted into your application,
|
108
|
+
This is required because `ActiveWaiter` is a Rails Engine mounted into your application,
|
109
109
|
and it doesn't know about the routes declared within your application.
|
110
|
+
|
111
|
+
#### Exceptions
|
112
|
+
|
113
|
+
When your job gets an exception, the error message will be written in the error message and passed along
|
114
|
+
to the user. If your job has a method `suppress_exceptions` that returns a truthy value (default false),
|
115
|
+
`ActiveWaiter::Job` will swallow the exception and not raise it - this means there will be no retry by
|
116
|
+
`ActiveJob`.
|
117
|
+
|
118
|
+
### Common Jobs
|
119
|
+
|
120
|
+
#### ActiveWaiter::EnumerableJob
|
121
|
+
|
122
|
+
If you need to wait, you're likely doing one thing slowly or many things. For the latter case, you can just
|
123
|
+
`include ActiveWaiter::EnumerableJob` and add a few interface methods
|
124
|
+
|
125
|
+
``` ruby
|
126
|
+
def before(*args); end # called once with arguments of `perform`
|
127
|
+
def enumerable; [] end # an Enumerable interface
|
128
|
+
def items_count; 1 end # called 0-n times, depending on enumerable
|
129
|
+
def foreach(item); end # called 0-n times, depending on enumerable
|
130
|
+
def after; end # called once
|
131
|
+
def result; end # called once
|
132
|
+
```
|
133
|
+
|
134
|
+
Here's an example from our test code, that will generate an array of range `0...count` and return the sum
|
135
|
+
of all the numbers
|
136
|
+
|
137
|
+
``` ruby
|
138
|
+
class LoopJob < ActiveJob::Base
|
139
|
+
include ActiveWaiter::EnumerableJob
|
140
|
+
|
141
|
+
attr_accessor :items_count, :enumerable, :result
|
142
|
+
|
143
|
+
def before(count)
|
144
|
+
@items_count = count
|
145
|
+
@enumerable = count.times
|
146
|
+
@result = 0
|
147
|
+
end
|
148
|
+
|
149
|
+
def foreach(item)
|
150
|
+
@result += item
|
151
|
+
end
|
152
|
+
end
|
153
|
+
```
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ActiveWaiter::EnumerableJob
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
include ActiveWaiter::Job
|
6
|
+
end
|
7
|
+
|
8
|
+
def perform(*args)
|
9
|
+
before(*args)
|
10
|
+
enumerable.each_with_index do |item, index|
|
11
|
+
foreach(item)
|
12
|
+
update_active_waiter(percentage: (100 * (index+1.to_f) / items_count))
|
13
|
+
end
|
14
|
+
after
|
15
|
+
result
|
16
|
+
end
|
17
|
+
|
18
|
+
def before(*_args); end # called once with arguments of `perform`
|
19
|
+
|
20
|
+
def enumerable; [] end # an Enumerable interface
|
21
|
+
|
22
|
+
def items_count; 1 end # called 0-n times, depending on enumerable
|
23
|
+
|
24
|
+
def foreach(_item); end # called 0-n times, depending on enumerable
|
25
|
+
|
26
|
+
def after; end # called once
|
27
|
+
|
28
|
+
def result; end # called once
|
29
|
+
end
|
data/lib/active_waiter/job.rb
CHANGED
@@ -13,7 +13,7 @@ module ActiveWaiter::Job
|
|
13
13
|
::ActiveWaiter.write(@active_waiter_options[:uid], {
|
14
14
|
error: $!.to_s,
|
15
15
|
})
|
16
|
-
raise
|
16
|
+
raise unless suppress_exceptions
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -24,4 +24,6 @@ module ActiveWaiter::Job
|
|
24
24
|
error: error,
|
25
25
|
}) if @active_waiter_options.try(:[], :uid)
|
26
26
|
end
|
27
|
+
|
28
|
+
def suppress_exceptions; false; end
|
27
29
|
end
|
data/lib/active_waiter.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_waiter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- choonkeat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: A simple mechanism allowing your users to wait for the completion of
|
56
70
|
your `ActiveJob`
|
57
71
|
email:
|
@@ -78,6 +92,7 @@ files:
|
|
78
92
|
- lib/active_waiter.rb
|
79
93
|
- lib/active_waiter/configuration.rb
|
80
94
|
- lib/active_waiter/engine.rb
|
95
|
+
- lib/active_waiter/enumerable_job.rb
|
81
96
|
- lib/active_waiter/job.rb
|
82
97
|
- lib/active_waiter/version.rb
|
83
98
|
- lib/tasks/waiter_tasks.rake
|