delayed_job_active_record_threaded 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +55 -3
- data/delayed_job_active_record_threaded.gemspec +1 -1
- data/lib/tasks/dj.rake +6 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 864851553076265c22eb06a51fbc06894bbaa3a5
|
4
|
+
data.tar.gz: 5cbfba03389e2369e1824e65abc7746dacbaad84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72e07e672c5ae64722d932a5a418fddbff0d2d40eadfc134bcd6a3f20eb9912722db28abe9b1dee17af433adcc9b8edda2fadadac91dea6621736a8de9e3dfc4
|
7
|
+
data.tar.gz: c00333cf69cffa44bf5ae44455acfce75d092607b6ee740058a509d31a27ab9b65e2c6ca9c3ecff88fa482c39d9eeb4d8205145d8cc67776edd0510881dde601
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
# DelayedJobActiveRecordThreaded
|
1
|
+
# DelayedJobActiveRecordThreaded [![Build Status](https://travis-ci.org/zxiest/delayed_job_active_record_threaded.png)](http://travis-ci.org/zxiest/delayed_job_active_record_threaded)
|
2
2
|
|
3
|
-
|
3
|
+
DelayedJob allows you to execute long-running jobs at a later time. For more information on how to create and delay a job, follow https://github.com/collectiveidea/delayed_job
|
4
|
+
|
5
|
+
This gem processes your delayed jobs with a single threaded process (instead of multiple processes).
|
6
|
+
This helps avoid database deadlocks and saves computing resources.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -16,9 +19,58 @@ Or install it yourself as:
|
|
16
19
|
|
17
20
|
$ gem install delayed_job_active_record_threaded
|
18
21
|
|
22
|
+
|
23
|
+
## Setup
|
24
|
+
Make sure to pick the correct setup method prior to proceeding:
|
25
|
+
|
26
|
+
### Fresh setup
|
27
|
+
Follow this setup method if you do have not been using delayed_job_active_record in your project and do not have a "delayed_jobs" table created:
|
28
|
+
|
29
|
+
$ rails generate delayed_job:active_record
|
30
|
+
$ rake db:migrate
|
31
|
+
|
32
|
+
### Upgrading from delayed_job_active_record
|
33
|
+
|
34
|
+
If you were previously using delayed_job_active_record, follow the steps below:
|
35
|
+
|
36
|
+
$ rails generate delayed_job:upgrade
|
37
|
+
$ rake db:migrate
|
38
|
+
|
39
|
+
This will add columns to your delayed_jobs table.
|
40
|
+
|
19
41
|
## Usage
|
20
42
|
|
21
|
-
|
43
|
+
For information on how to create delayed_jobs and enqueue them, follow https://github.com/collectiveidea/delayed_job
|
44
|
+
|
45
|
+
In order to start the threaded process this gem provides, use the following:
|
46
|
+
|
47
|
+
### Defaults
|
48
|
+
|
49
|
+
$ bundle exec rake delayed_job:start
|
50
|
+
or
|
51
|
+
$ bundle exec rake dj:start
|
52
|
+
|
53
|
+
### With Options
|
54
|
+
|
55
|
+
The default task processes items belonging to all the queues. This is, most of times, not desirable as tasks with higher priority in a given queue take precedence over tasks in another queue.
|
56
|
+
|
57
|
+
You can have multiple queues processed simultaneously, each with its own options.
|
58
|
+
In the example below, we assume you have an "ebooks" and an "albums" queues.
|
59
|
+
|
60
|
+
The command below will process the queues ebooks and albums simultaneously
|
61
|
+
$ bundle exec rake "dj:start[ebooks&albums]"
|
62
|
+
|
63
|
+
$ bundle exec rake "dj:start[ebooks[workers_number]=16&ebooks[worker_timeout]=60&albums[workers_number]=32&albums[worker_timeout]=120]"
|
64
|
+
|
65
|
+
The expression "ebooks[workers_number]=16&ebooks[worker_timeout]=60" is a parsed similarly to a URL's query string and would be converted into the following hash:
|
66
|
+
|
67
|
+
{"ebooks"=>{"workers_number"=>"16", "worker_timeout"=>"60"}, "albums"=>{"workers_number"=>"32", "worker_timeout"=>"120"}}
|
68
|
+
|
69
|
+
The rake task above will start a process in the background and process two queues, "ebooks" with 16 working threads and times out after 60 seconds and "albums" with 32 working threads and times out after 120 seconds.
|
70
|
+
|
71
|
+
Default options:
|
72
|
+
workers_number: 16
|
73
|
+
worker_timeout: 60
|
22
74
|
|
23
75
|
## Contributing
|
24
76
|
|
data/lib/tasks/dj.rake
CHANGED
@@ -2,11 +2,11 @@ require 'rack/utils'
|
|
2
2
|
|
3
3
|
namespace :dj do
|
4
4
|
task :run, [:args_expr ] => :environment do |t,args|
|
5
|
-
Rake::Task["delayed_job:run"].invoke(args[:args_expr]
|
5
|
+
Rake::Task["delayed_job:run"].invoke(args[:args_expr])
|
6
6
|
end
|
7
7
|
|
8
8
|
task :start, [:args_expr ] => :environment do |t,args|
|
9
|
-
Rake::Task["delayed_job:start"].invoke(args[:args_expr]
|
9
|
+
Rake::Task["delayed_job:start"].invoke(args[:args_expr])
|
10
10
|
end
|
11
11
|
|
12
12
|
task :stop, [:args_expr ] => :environment do |t,args|
|
@@ -18,7 +18,7 @@ namespace :dj do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
task :print_options, [:args_expr ] => :environment do |t,args|
|
21
|
-
Rake::Task["delayed_job:print_options"].invoke(args[:args_expr]
|
21
|
+
Rake::Task["delayed_job:print_options"].invoke(args[:args_expr])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -72,8 +72,8 @@ namespace :delayed_job do
|
|
72
72
|
task :start, [ :args_expr ] => :environment do |t, args|
|
73
73
|
puts "#{args[:args_expr]}"
|
74
74
|
|
75
|
-
cmd = %(if [ -f #{dj_pid} ] && [ -n `cat #{dj_pid}` ] &&
|
76
|
-
(bundle exec rake "delayed_job:run[#{args[:args_expr]}]" >> log/delayed_job.log 2>&1) & (echo $! >
|
75
|
+
cmd = %(if [ -f #{dj_pid} ] && [ -n `cat #{dj_pid}` ] && ps -p `cat #{dj_pid}` > /dev/null; then kill `cat #{dj_pid}`; fi
|
76
|
+
(bundle exec rake "delayed_job:run[#{args[:args_expr]}]" >> log/delayed_job.log 2>&1) & (echo $! > #{dj_pid})
|
77
77
|
)
|
78
78
|
|
79
79
|
puts "executing: #{cmd}"
|
@@ -83,7 +83,7 @@ namespace :delayed_job do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
task :stop => :environment do |t, args|
|
86
|
-
cmd = %(if [ -f #{dj_pid} ] && [ -n `cat #{dj_pid}` ] &&
|
86
|
+
cmd = %(if [ -f #{dj_pid} ] && [ -n `cat #{dj_pid}` ] && ps -p `cat #{dj_pid}` > /dev/null; then kill -9 `cat #{dj_pid}`; fi)
|
87
87
|
|
88
88
|
# execute cmd
|
89
89
|
%x(#{cmd})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_job_active_record_threaded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdo Achkar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -163,6 +163,7 @@ extra_rdoc_files: []
|
|
163
163
|
files:
|
164
164
|
- .gitignore
|
165
165
|
- .travis.yml
|
166
|
+
- CHANGELOG.md
|
166
167
|
- Gemfile
|
167
168
|
- LICENSE.txt
|
168
169
|
- README.md
|