resque-kawai 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ locks
4
4
  *.gem
5
5
  *.log
6
6
  .bundle
7
+ Gemfile.lock
data/README.md CHANGED
@@ -10,13 +10,9 @@ gem 'resque-kawai'
10
10
 
11
11
  rails generate rq:add bla
12
12
 
13
- And add to config/application.rb
14
-
15
- config.autoload_paths += %W( #{config.root}/app/models/resque )
16
-
17
13
  Consumer
18
14
  --------
19
- app/models/resque/rq_bla.rb
15
+ app/workers/rq_bla.rb
20
16
 
21
17
  ``` ruby
22
18
  class RqBla < RqQueue
@@ -41,7 +37,7 @@ Insert event into queue like this:
41
37
  RqBla.add_event(:some_method2, some_x)
42
38
 
43
39
 
44
- Logger for this consumer: Rails.root/log/resque/bla.log
40
+ Logger for this consumer: Rails.root/log/workers/bla.log
45
41
 
46
42
 
47
43
 
@@ -68,3 +64,12 @@ Usefull in specs
68
64
  ```
69
65
 
70
66
  When code call RqBla.some_method1(a,b,c) this would be convert into RqBla.new.some_method1(a,b,c)
67
+
68
+
69
+ ### Insert event with Resque-scheduler
70
+
71
+ ``` ruby
72
+ RqBla.add_event_in(10.seconds, :some_method1, 1, 2, 3)
73
+
74
+ RqBla.enqueue_in(10.seconds, :some_method1, 1, 2, 3)
75
+ ```
@@ -6,8 +6,8 @@ if Rails::VERSION::MAJOR >= 3
6
6
  source_root File.expand_path("../templates", __FILE__)
7
7
 
8
8
  def add_files
9
- template "consumer.rb", "app/models/resque/rq_#{file_path}.rb"
10
- template "spec.rb", "spec/models/resque/rq_#{file_path}_spec.rb"
9
+ template "consumer.rb", "app/workers/rq_#{file_path}.rb"
10
+ template "spec.rb", "spec/workers/rq_#{file_path}_spec.rb"
11
11
  end
12
12
  end
13
13
  end
@@ -20,8 +20,8 @@ if Rails::VERSION::MAJOR == 2
20
20
  class RqAddGenerator < Rails::Generator::NamedBase
21
21
  def manifest
22
22
  record do |m|
23
- m.template "consumer.rb", "app/models/bin/rq_#{file_path}.rb"
24
- m.template "spec.rb", "spec/models/bin/rq_#{file_path}_spec.rb"
23
+ m.template "consumer.rb", "app/workers/rq_#{file_path}.rb"
24
+ m.template "spec.rb", "spec/workers/rq_#{file_path}_spec.rb"
25
25
  end
26
26
  end
27
27
  end
@@ -24,14 +24,34 @@ class RqQueue
24
24
  def self.queue_name
25
25
  @queue
26
26
  end
27
+
28
+
27
29
 
28
30
  def self.add_event(method_name, *args)
29
31
  Resque.enqueue(self, method_name.to_s, args)
30
32
  end
31
33
 
34
+ def self.enqueue(method_name, *args)
35
+ add_event method_name, *args
36
+ end
37
+
32
38
  def self.method_missing(method, *args)
33
39
  add_event(method, *args)
34
40
  end
41
+
42
+
43
+
44
+ # For resque-scheduler
45
+ def self.add_event_in(times, method_name, *args)
46
+ Resque.enqueue_in(times, self, method_name.to_s, args)
47
+ end
48
+
49
+ # For resque-scheduler
50
+ def self.enqueue_in(times, method_name, *args)
51
+ add_event_in(times, method_name, *args)
52
+ end
53
+
54
+
35
55
 
36
56
  def self.logger
37
57
  @logger ||= Logger.new(logger_path).tap do |logger|
@@ -53,7 +73,8 @@ class RqQueue
53
73
  logger.info "done #{method_name}, #{"%.6f" % (Time.now - start_time)} s" if benchmark
54
74
 
55
75
  rescue => ex
56
- logger.error "!Failed event: #{method_name} => #{ex.message}"
76
+ logger.error "!Failed event: #{method_name} => #{ex.message}"
77
+ notify_about_error(ex)
57
78
  raise ex
58
79
  end
59
80
 
@@ -72,7 +93,7 @@ class RqQueue
72
93
 
73
94
  def logger_path
74
95
  @logger_path ||= begin
75
- "#{Rails.root}/log/resque/#{extract_queue_name}.log"
96
+ "#{Rails.root}/log/workers/#{extract_queue_name}.log"
76
97
  end
77
98
  end
78
99
 
@@ -87,4 +108,8 @@ class RqQueue
87
108
  self.class.queue_name
88
109
  end
89
110
 
111
+ def self.notify_about_error(exception)
112
+ # stub
113
+ end
114
+
90
115
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Rq
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
@@ -23,5 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency 'resque'
24
24
  s.add_development_dependency "rspec"
25
25
  s.add_development_dependency "rake"
26
+ s.add_development_dependency "json"
26
27
 
27
- end
28
+ end
@@ -62,7 +62,22 @@ describe RqQueue do
62
62
  it "should insert event with custom method" do
63
63
  Resque.should_receive(:enqueue).with(RqTest, 'super', [[1, 2, 3]])
64
64
  RqTest.add_event(:super, [1, 2, 3])
65
- end
65
+ end
66
+
67
+ it "should insert event with custom method enqueue" do
68
+ Resque.should_receive(:enqueue).with(RqTest, 'super', [1, 2, 3])
69
+ RqTest.enqueue(:super, 1, 2, 3)
70
+ end
71
+
72
+ it "enqueue in" do
73
+ Resque.should_receive(:enqueue_in).with(10, RqTest, 'super', [1, 2, 3])
74
+ RqTest.enqueue_in(10, :super, 1, 2, 3)
75
+ end
76
+
77
+ it "add event in" do
78
+ Resque.should_receive(:enqueue_in).with(10, RqTest, 'super', [1, 2, 3])
79
+ RqTest.add_event_in(10, :super, 1, 2, 3)
80
+ end
66
81
 
67
82
  describe "consume" do
68
83
  before :each do
metadata CHANGED
@@ -1,91 +1,105 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: resque-kawai
3
- version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 5
10
- version: 0.1.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Makarchev Konstantin
14
9
  autorequire: resque-kawai.rb
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-05-11 00:00:00 +04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: activesupport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: resque
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: resque
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
47
38
  type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: rspec
51
39
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
53
49
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
61
54
  type: :development
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
64
63
  name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
65
71
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
67
73
  none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
75
86
  type: :development
76
- version_requirements: *id004
77
- description: Syntax sugar for Resque consumers. Each consumer is a class, with clean interface, and custom logger. Usefull when count of different events ~100 and more.
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Syntax sugar for Resque consumers. Each consumer is a class, with clean
95
+ interface, and custom logger. Usefull when count of different events ~100 and more.
78
96
  email: kostya27@gmail.com
79
97
  executables: []
80
-
81
98
  extensions: []
82
-
83
99
  extra_rdoc_files: []
84
-
85
- files:
100
+ files:
86
101
  - .gitignore
87
102
  - Gemfile
88
- - Gemfile.lock
89
103
  - LICENSE
90
104
  - README.md
91
105
  - Rakefile
@@ -99,39 +113,35 @@ files:
99
113
  - spec/rq_queue_spec.rb
100
114
  - spec/spec_helper.rb
101
115
  - spec/test_class.rb
102
- has_rdoc: true
103
116
  homepage: http://github.com/kostya/resque-kawai
104
117
  licenses: []
105
-
106
118
  post_install_message:
107
119
  rdoc_options: []
108
-
109
- require_paths:
120
+ require_paths:
110
121
  - lib
111
- required_ruby_version: !ruby/object:Gem::Requirement
122
+ required_ruby_version: !ruby/object:Gem::Requirement
112
123
  none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
118
129
  - 0
119
- version: "0"
120
- required_rubygems_version: !ruby/object:Gem::Requirement
130
+ hash: -858566573
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
132
  none: false
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- hash: 3
126
- segments:
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ segments:
127
138
  - 0
128
- version: "0"
139
+ hash: -858566573
129
140
  requirements: []
130
-
131
141
  rubyforge_project:
132
- rubygems_version: 1.3.7
142
+ rubygems_version: 1.8.24
133
143
  signing_key:
134
144
  specification_version: 3
135
- summary: Syntax sugar for Resque consumers. Each consumer is a class, with clean interface, and custom logger. Usefull when count of different events ~100 and more.
145
+ summary: Syntax sugar for Resque consumers. Each consumer is a class, with clean interface,
146
+ and custom logger. Usefull when count of different events ~100 and more.
136
147
  test_files: []
137
-
@@ -1,51 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- resque-kawai (0.1.4)
5
- activesupport
6
- resque
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- activesupport (3.2.3)
12
- i18n (~> 0.6)
13
- multi_json (~> 1.0)
14
- diff-lcs (1.1.3)
15
- i18n (0.6.0)
16
- multi_json (1.3.2)
17
- rack (1.4.1)
18
- rack-protection (1.2.0)
19
- rack
20
- rake (0.9.2.2)
21
- redis (2.2.2)
22
- redis-namespace (1.0.3)
23
- redis (< 3.0.0)
24
- resque (1.20.0)
25
- multi_json (~> 1.0)
26
- redis-namespace (~> 1.0.2)
27
- sinatra (>= 0.9.2)
28
- vegas (~> 0.1.2)
29
- rspec (2.9.0)
30
- rspec-core (~> 2.9.0)
31
- rspec-expectations (~> 2.9.0)
32
- rspec-mocks (~> 2.9.0)
33
- rspec-core (2.9.0)
34
- rspec-expectations (2.9.1)
35
- diff-lcs (~> 1.1.3)
36
- rspec-mocks (2.9.0)
37
- sinatra (1.3.2)
38
- rack (~> 1.3, >= 1.3.6)
39
- rack-protection (~> 1.2)
40
- tilt (~> 1.3, >= 1.3.3)
41
- tilt (1.3.3)
42
- vegas (0.1.11)
43
- rack (>= 1.0.0)
44
-
45
- PLATFORMS
46
- ruby
47
-
48
- DEPENDENCIES
49
- rake
50
- resque-kawai!
51
- rspec