simple_worker 1.0.14 → 2.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -80,13 +80,6 @@ Let's say someone does something in your app and you want to send an email about
80
80
 
81
81
  This will send it off to the SimpleWorker cloud.
82
82
 
83
- To queue worker without uploading you could try to do following:
84
-
85
- data[:attr_encoded] = Base64.encode64({'@to'=>'example@email.com'}.to_json)
86
- data[:sw_config] = SimpleWorker.config.get_atts_to_send
87
- SimpleWorker.service.queue('EmailWorker', data)
88
-
89
-
90
83
  Setting Priority
91
84
  ----------------------------------------------
92
85
 
@@ -41,15 +41,11 @@ module SimpleWorker
41
41
  def merge_gem(gem_name, options={})
42
42
  gem_info = SimpleWorker::MergeHelper.create_gem_info(gem_name, options)
43
43
  @merged_gems[gem_name.to_s] = gem_info
44
- reqs = gem_info[:require].is_a?(Array) ? gem_info[:require] : [gem_info[:require]]
45
- reqs.each do |r|
46
- r2 = "#{gem_info[:path]}/lib/#{r}"
47
- begin
48
- SimpleWorker.logger.debug 'requiring ' + r2
49
- require r2
50
- rescue LoadError=>ex
51
- raise "Gem #{gem_name} was found, but we could not load the file '#{r2}'. You may need to use :require=>x.........."
52
- end
44
+ #puts 'before require ' + (options[:require] || gem_name)
45
+ begin
46
+ require gem_info[:require]
47
+ rescue LoadError=>ex
48
+ raise "Gem #{gem_name} was found, but we could not load the file '#{options[:require] || gem_name}.rb'. You may need to use :require=>x.........."
53
49
  end
54
50
  end
55
51
 
@@ -68,7 +64,7 @@ module SimpleWorker
68
64
  f2 = SimpleWorker::MergeHelper.check_for_file(mailer, @caller_file)
69
65
  basename = File.basename(mailer, f2[:extname])
70
66
  path_to_templates = params[:path_to_templates] || File.join(Rails.root, "app/views/#{basename}")
71
- @merged_mailers[basename] = {:name=>basename, :path_to_templates=>path_to_templates, :filename => f2[:path]}.merge!(params)
67
+ @merged_mailers[basename] = {:name=>basename, :path_to_templates=>path_to_templates, :filename => mailer}.merge!(params)
72
68
  end
73
69
 
74
70
  def merge_folder(path)
@@ -155,7 +151,7 @@ module SimpleWorker
155
151
  # puts 'run_local'
156
152
  set_auto_attributes
157
153
  init_database
158
- init_mailer
154
+ init_mailer
159
155
  begin
160
156
  run
161
157
  rescue => ex
@@ -167,11 +163,11 @@ module SimpleWorker
167
163
  end
168
164
  end
169
165
 
170
- def init_mailer
166
+ def init_mailer
171
167
  if SimpleWorker.config.mailer
172
168
  require 'action_mailer'
173
- ActionMailer::Base.raise_delivery_errors = true
174
- ActionMailer::Base.smtp_settings = (SimpleWorker.config.mailer)
169
+ ActionMailer::Base.raise_delivery_errors = true
170
+ ActionMailer::Base.smtp_settings = (SimpleWorker.config.mailer)
175
171
  end
176
172
  end
177
173
 
@@ -1,9 +1,11 @@
1
1
  # This is the file that gets executed on the server.
2
2
 
3
+
3
4
  def init_database_connection(sw_config)
4
5
  if sw_config
5
6
  db_config = sw_config['database']
6
7
  if db_config
8
+ #@logger.info "Connecting to database using ActiveRecord..."
7
9
  require 'active_record'
8
10
  ActiveRecord::Base.establish_connection(db_config)
9
11
  end
@@ -75,3 +77,22 @@ def init_worker_service_for_runner(job_data)
75
77
  end
76
78
  end
77
79
 
80
+
81
+ run_data = JSON.load(File.open(run_data_file))
82
+ # Load in job data
83
+ job_data = JSON.load(File.open(job_data_file))
84
+ job_data.merge!(run_data)
85
+ puts 'job_data=' + job_data.inspect
86
+
87
+ sw_config = job_data['sw_config']
88
+ init_database_connection(sw_config)
89
+ init_mailer(sw_config)
90
+ SimpleWorker.disable_queueing()
91
+ runner_class = get_class_to_run(job_data['class_name'])
92
+ SimpleWorker.running_class = runner_class
93
+ runner = init_runner(runner_class, job_data, dirname)
94
+ init_worker_service_for_runner(job_data)
95
+ SimpleWorker.enable_queueing()
96
+
97
+ # Let's run it!
98
+ runner_return_data = runner.run
@@ -122,11 +122,6 @@ module SimpleWorker
122
122
  #tmp_file = File.join(Dir.tmpdir(), File.basename(filename))
123
123
  tmp_file = File.join(Dir.tmpdir(), 'runner.rb')
124
124
  File.open(tmp_file, "w") do |f|
125
- File.open(File.join(File.dirname(__FILE__), "server", 'runner.rb'), 'r') do |fr|
126
- while line = fr.gets
127
- f.write line
128
- end
129
- end
130
125
  f.write("begin\n")#error handling block start
131
126
  f.write("
132
127
  # Find environment (-e)
@@ -150,36 +145,15 @@ ARGV.each do |arg|
150
145
  i+=1
151
146
  end
152
147
 
153
-
154
148
  # Change to user directory
155
149
  #puts 'dirname=' + dirname.inspect
156
150
  Dir.chdir(dirname)
157
- require 'json'
158
- run_data = JSON.load(File.open(run_data_file))
159
- # Load in job data
160
- job_data = JSON.load(File.open(job_data_file))
161
- job_data.merge!(run_data)
162
- #puts 'job_data=' + job_data.inspect
163
-
164
- sw_config = job_data['sw_config']
165
151
  ")
166
152
 
167
153
 
168
154
  f.write("require 'simple_worker'\n")
169
155
 
170
156
 
171
- File.open(File.join(File.dirname(__FILE__), 'server', 'overrides.rb'), 'r') do |fr|
172
- while line = fr.gets
173
- f.write line
174
- end
175
- end
176
-
177
- # Now we must disable queuing while loading up classes. This is from the overrides.rb file
178
- f.write("
179
- SimpleWorker.disable_queueing()
180
- ")
181
-
182
-
183
157
  # add some rails stuff if using Rails
184
158
  if defined?(Rails)
185
159
  f.write "module Rails
@@ -193,6 +167,15 @@ end
193
167
  "
194
168
  end
195
169
 
170
+ if SimpleWorker.config.database && !SimpleWorker.config.database.empty?
171
+ f.write "require 'active_record'\n"
172
+ end
173
+
174
+ if merged_mailers && !merged_mailers.empty?
175
+ # todo: isn't 'action_mailer already required in railtie?
176
+ f.write "require 'action_mailer'\n"
177
+ f.write "ActionMailer::Base.prepend_view_path('templates')\n"
178
+ end
196
179
  #if SimpleWorker.config.auto_merge
197
180
  merged_gems.each_pair do |k, gem|
198
181
  SimpleWorker.logger.debug "Bundling gem #{gem[:name]}..."
@@ -214,19 +197,17 @@ end
214
197
  # end
215
198
  end
216
199
 
217
- if merged_mailers && !merged_mailers.empty?
218
- # todo: isn't 'action_mailer already required in railtie?
219
- f.write "require 'action_mailer'\n"
220
- f.write "init_mailer(sw_config)\n"
221
- f.write "ActionMailer::Base.prepend_view_path('templates')\n"
222
- end
223
- f.write "init_database_connection(sw_config)\n"
224
200
  if SimpleWorker.config.extra_requires
225
201
  SimpleWorker.config.extra_requires.each do |r|
226
202
  f.write "require '#{r}'\n"
227
203
  end
228
204
  end
229
205
 
206
+ File.open(File.join(File.dirname(__FILE__), 'server', 'overrides.rb'), 'r') do |fr|
207
+ while line = fr.gets
208
+ f.write line
209
+ end
210
+ end
230
211
 
231
212
  merged.each_pair do |k, v|
232
213
  if v[:extname] == ".rb"
@@ -238,23 +219,13 @@ end
238
219
  end
239
220
  #end
240
221
  #f.write File.open(filename, 'r') { |mo| mo.read }
241
- f.write("require_relative '#{File.basename(filename)}'\n")
242
-
243
-
244
-
245
- f.write("
246
- runner_class = get_class_to_run(job_data['class_name'])
247
- SimpleWorker.running_class = runner_class
248
- runner = init_runner(runner_class, job_data, dirname)
249
- init_worker_service_for_runner(job_data)
250
-
251
- # lastly, reenable queueing
252
- SimpleWorker.enable_queueing()
253
-
254
- # Let's run it!
255
- runner_return_data = runner.run
256
- ")
222
+ f.write("require_relative '#{File.basename(filename)}'")
257
223
 
224
+ File.open(File.join(File.dirname(__FILE__), "server", 'runner.rb'), 'r') do |fr|
225
+ while line = fr.gets
226
+ f.write line
227
+ end
228
+ end
258
229
  #error handling block - end
259
230
  f.write("\nrescue Exception => ex
260
231
  $stderr.puts '_error_from_sw_'
@@ -333,7 +304,6 @@ end
333
304
  # puts " MERGED MAILERS" + merged_mailers.inspect
334
305
  merged_mailers.each_pair do |k, mailer|
335
306
  SimpleWorker.logger.debug "Collecting mailer #{mailer[:name]}"
336
- puts "MAILER #{mailer.inspect}"
337
307
  f.add(File.basename(mailer[:filename]), mailer[:filename])
338
308
  path = mailer[:path_to_templates]
339
309
  Dir["#{path}/**/**"].each do |file|
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_worker
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.14
4
+ prerelease: 6
5
+ version: 2.0.0.beta.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Travis Reeder
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-11-03 00:00:00 Z
13
+ date: 2011-09-28 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: zip
@@ -44,7 +44,6 @@ extra_rdoc_files:
44
44
  - README.markdown
45
45
  files:
46
46
  - lib/generators/simple_worker/simple_worker_generator.rb
47
- - lib/generators/simple_worker/templates/template_worker.erb
48
47
  - lib/simple_worker.rb
49
48
  - lib/simple_worker/api.rb
50
49
  - lib/simple_worker/base.rb
@@ -75,9 +74,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
74
  required_rubygems_version: !ruby/object:Gem::Requirement
76
75
  none: false
77
76
  requirements:
78
- - - ">="
77
+ - - ">"
79
78
  - !ruby/object:Gem::Version
80
- version: "0"
79
+ version: 1.3.1
81
80
  requirements: []
82
81
 
83
82
  rubyforge_project:
@@ -1,7 +0,0 @@
1
- class <%= @camel %> < SimpleWorker::Base
2
-
3
- def run
4
- log "Your code goes in this bit"
5
- end
6
-
7
- end