toro 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +531 -0
- data/lib/generators/toro/install/install_generator.rb +25 -0
- data/lib/generators/toro/install/templates/create_toro_jobs.rb +9 -0
- data/lib/tasks/tasks.rb +19 -0
- data/lib/toro.rb +51 -1
- data/lib/toro/actor.rb +8 -0
- data/lib/toro/actor_manager.rb +11 -0
- data/lib/toro/cli.rb +87 -0
- data/lib/toro/client.rb +17 -0
- data/lib/toro/database.rb +38 -0
- data/lib/toro/fetcher.rb +40 -0
- data/lib/toro/job.rb +38 -0
- data/lib/toro/listener.rb +44 -0
- data/lib/toro/logging.rb +80 -0
- data/lib/toro/manager.rb +143 -0
- data/lib/toro/middleware/chain.rb +81 -0
- data/lib/toro/middleware/server/error.rb +19 -0
- data/lib/toro/middleware/server/error_storage.rb +22 -0
- data/lib/toro/middleware/server/properties.rb +15 -0
- data/lib/toro/middleware/server/retry.rb +25 -0
- data/lib/toro/monitor.rb +34 -0
- data/lib/toro/monitor/custom_views.rb +26 -0
- data/lib/toro/monitor/engine.rb +11 -0
- data/lib/toro/monitor/time_formatter.rb +27 -0
- data/lib/toro/processor.rb +48 -0
- data/lib/toro/railtie.rb +9 -0
- data/lib/toro/sql/down.sql +4 -0
- data/lib/toro/sql/up.sql +68 -0
- data/lib/toro/version.rb +1 -1
- data/lib/toro/worker.rb +44 -0
- metadata +49 -22
data/lib/toro/railtie.rb
ADDED
data/lib/toro/sql/up.sql
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
DO $$ BEGIN
|
2
|
+
|
3
|
+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
4
|
+
CREATE EXTENSION IF NOT EXISTS "hstore";
|
5
|
+
|
6
|
+
CREATE TABLE toro_jobs (
|
7
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
8
|
+
queue TEXT NOT NULL CHECK (LENGTH(queue) > 0),
|
9
|
+
class_name TEXT NOT NULL CHECK (LENGTH(class_name) > 0),
|
10
|
+
args TEXT NOT NULL,
|
11
|
+
name TEXT,
|
12
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
13
|
+
scheduled_at TIMESTAMPTZ,
|
14
|
+
started_at TIMESTAMPTZ,
|
15
|
+
finished_at TIMESTAMPTZ,
|
16
|
+
status TEXT NOT NULL CHECK (LENGTH(status) > 0),
|
17
|
+
started_by TEXT,
|
18
|
+
properties HSTORE
|
19
|
+
);
|
20
|
+
|
21
|
+
END $$ LANGUAGE plpgsql;
|
22
|
+
|
23
|
+
CREATE FUNCTION toro_notify() RETURNS TRIGGER AS $$ BEGIN
|
24
|
+
PERFORM pg_notify('toro_' || new.queue, '');
|
25
|
+
RETURN NULL;
|
26
|
+
END $$ LANGUAGE plpgsql;
|
27
|
+
|
28
|
+
CREATE TRIGGER toro_notify
|
29
|
+
AFTER INSERT ON toro_jobs
|
30
|
+
FOR EACH ROW
|
31
|
+
EXECUTE PROCEDURE toro_notify();
|
32
|
+
|
33
|
+
CREATE FUNCTION toro_pop(queues TEXT[], process_name TEXT) RETURNS toro_jobs AS $$
|
34
|
+
DECLARE
|
35
|
+
result toro_jobs;
|
36
|
+
BEGIN
|
37
|
+
WITH next_job AS (
|
38
|
+
SELECT
|
39
|
+
*
|
40
|
+
FROM
|
41
|
+
toro_jobs
|
42
|
+
WHERE
|
43
|
+
queue = ANY(queues)
|
44
|
+
AND (
|
45
|
+
status = 'queued'
|
46
|
+
OR
|
47
|
+
(status = 'scheduled' AND scheduled_at <= NOW())
|
48
|
+
)
|
49
|
+
ORDER BY
|
50
|
+
created_at ASC
|
51
|
+
LIMIT 1
|
52
|
+
)
|
53
|
+
UPDATE
|
54
|
+
toro_jobs
|
55
|
+
SET
|
56
|
+
status = 'running',
|
57
|
+
started_at = NOW(),
|
58
|
+
started_by = process_name
|
59
|
+
FROM
|
60
|
+
next_job
|
61
|
+
WHERE
|
62
|
+
toro_jobs.id = next_job.id
|
63
|
+
RETURNING
|
64
|
+
next_job.* INTO result;
|
65
|
+
RETURN result;
|
66
|
+
END $$ LANGUAGE plpgsql;
|
67
|
+
|
68
|
+
CREATE INDEX toro_jobs_queue_created_at_index ON toro_jobs (queue, created_at) WHERE status = 'queued' OR status = 'scheduled';
|
data/lib/toro/version.rb
CHANGED
data/lib/toro/worker.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Toro
|
2
|
+
module Worker
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def perform_async(*args)
|
9
|
+
create_job(args: args, queue: queue)
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform_at(time, *args)
|
13
|
+
create_job(args: args, queue: queue, scheduled_at: time, status: 'scheduled')
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform_in(interval, *args)
|
17
|
+
time = Time.now + interval
|
18
|
+
perform_at(time, *args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_job(item)
|
22
|
+
Toro::Client.create_job(normalize_job(item))
|
23
|
+
end
|
24
|
+
|
25
|
+
def normalize_job(item)
|
26
|
+
name = respond_to?(:job_name) ? send(:job_name, *(item[:args])) : nil
|
27
|
+
{ class_name: self.name, name: name }.merge(item)
|
28
|
+
end
|
29
|
+
|
30
|
+
def queue
|
31
|
+
toro_options[:queue]
|
32
|
+
end
|
33
|
+
|
34
|
+
def toro_options(options={})
|
35
|
+
@toro_options ||= {
|
36
|
+
queue: Toro.options[:default_queue],
|
37
|
+
retry_interval: nil
|
38
|
+
}
|
39
|
+
@toro_options.merge!(options)
|
40
|
+
@toro_options
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,16 +9,16 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: celluloid
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 0.15.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,15 +26,15 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 0.15.2
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: rails
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
37
|
+
version: '3.0'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,15 +42,15 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
45
|
+
version: '3.0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: pg
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0
|
53
|
+
version: '0'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,15 +58,15 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
61
|
+
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: nested-hstore
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '0'
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,9 +74,9 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
77
|
+
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: slim
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -92,7 +92,7 @@ dependencies:
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
95
|
+
name: jquery-datatables-rails
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
@@ -108,14 +108,14 @@ dependencies:
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
111
|
+
name: rails-datatables
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
115
115
|
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
|
-
type: :
|
118
|
+
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
@@ -124,7 +124,7 @@ dependencies:
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
127
|
+
name: appraisal
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
@@ -140,7 +140,7 @@ dependencies:
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
|
-
name:
|
143
|
+
name: rspec
|
144
144
|
requirement: !ruby/object:Gem::Requirement
|
145
145
|
none: false
|
146
146
|
requirements:
|
@@ -155,14 +155,41 @@ dependencies:
|
|
155
155
|
- - ! '>='
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
|
-
description:
|
158
|
+
description: Full-featured background processing for Ruby & PostgreSQL
|
159
159
|
email:
|
160
160
|
- tombenner@gmail.com
|
161
161
|
executables: []
|
162
162
|
extensions: []
|
163
163
|
extra_rdoc_files: []
|
164
164
|
files:
|
165
|
+
- lib/generators/toro/install/install_generator.rb
|
166
|
+
- lib/generators/toro/install/templates/create_toro_jobs.rb
|
167
|
+
- lib/tasks/tasks.rb
|
168
|
+
- lib/toro/actor.rb
|
169
|
+
- lib/toro/actor_manager.rb
|
170
|
+
- lib/toro/cli.rb
|
171
|
+
- lib/toro/client.rb
|
172
|
+
- lib/toro/database.rb
|
173
|
+
- lib/toro/fetcher.rb
|
174
|
+
- lib/toro/job.rb
|
175
|
+
- lib/toro/listener.rb
|
176
|
+
- lib/toro/logging.rb
|
177
|
+
- lib/toro/manager.rb
|
178
|
+
- lib/toro/middleware/chain.rb
|
179
|
+
- lib/toro/middleware/server/error.rb
|
180
|
+
- lib/toro/middleware/server/error_storage.rb
|
181
|
+
- lib/toro/middleware/server/properties.rb
|
182
|
+
- lib/toro/middleware/server/retry.rb
|
183
|
+
- lib/toro/monitor/custom_views.rb
|
184
|
+
- lib/toro/monitor/engine.rb
|
185
|
+
- lib/toro/monitor/time_formatter.rb
|
186
|
+
- lib/toro/monitor.rb
|
187
|
+
- lib/toro/processor.rb
|
188
|
+
- lib/toro/railtie.rb
|
189
|
+
- lib/toro/sql/down.sql
|
190
|
+
- lib/toro/sql/up.sql
|
165
191
|
- lib/toro/version.rb
|
192
|
+
- lib/toro/worker.rb
|
166
193
|
- lib/toro.rb
|
167
194
|
- MIT-LICENSE
|
168
195
|
- Rakefile
|
@@ -191,5 +218,5 @@ rubyforge_project:
|
|
191
218
|
rubygems_version: 1.8.24
|
192
219
|
signing_key:
|
193
220
|
specification_version: 3
|
194
|
-
summary:
|
221
|
+
summary: Full-featured background processing for Ruby & PostgreSQL
|
195
222
|
test_files: []
|