simple_worker 2.0.0.beta.5 → 2.0.0.beta.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,54 +59,42 @@ module SimpleWorker
59
59
  end
60
60
 
61
61
  def get(method, params={}, options={})
62
- #begin
63
- # ClientHelper.run_http(host, access_key, secret_key, :get, method, nil, params)
64
- full_url = url(method)
65
- all_params = add_params(method,params)
66
-
67
- url_plus_params = append_params(full_url, all_params)
68
- resp = RestClient.get(url_plus_params, headers)
69
-
70
- parse_response(resp, options)
71
-
72
- # Was:
73
- #parse_response RestClient.get(append_params(url(method), add_params(method, params)), headers), options
74
- #rescue RestClient::Exception => ex
75
- # process_ex(ex)
76
- #end
62
+ full_url = url(method)
63
+ all_params = add_params(method, params)
64
+
65
+ url_plus_params = append_params(full_url, all_params)
66
+ @logger.debug 'get url=' + url_plus_params
67
+ resp = RestClient.get(url_plus_params, headers)
68
+
69
+ parse_response(resp, options)
70
+
77
71
  end
78
72
 
79
73
  def post_file(method, file, params={}, options={})
80
74
  begin
81
- #params.delete("runtime")
82
- #params["runtime"]='ruby'
83
- #params.delete("file_name")
84
- #params["file_name"] = "runner.rb"
85
75
  data = add_params(method, params).to_json
86
76
  @logger.debug "data = " + data
87
77
  @logger.debug "params = " + params.inspect
88
78
  @logger.debug "options = " + options.inspect
89
- token = params["oauth"]
90
- parse_response RestClient.post(url(method) + "?oauth="+token, {:data => data, :file => file}, :content_type => 'application/json', :accept => :json), options
91
- #parse_response(RestClient.post(append_params(url(method), add_params(method, params)), {:data => data, :file => file}, :content_type => 'application/json'), options)
92
- rescue RestClient::Exception => ex
79
+ parse_response RestClient.post(url(method) + "?oauth=" + token, {:data => data, :file => file}, :content_type => 'application/json', :accept => :json), options
80
+ #parse_response(RestClient.post(append_params(url(method), add_params(method, params)), {:data => data, :file => file}, :content_type => 'application/json'), options)
81
+ rescue RestClient::Exception => ex
93
82
  process_ex(ex)
94
83
  end
95
84
  end
96
85
 
97
86
  def post(method, params={}, options={})
98
- @logger.debug "params = " + params.inspect
99
- @logger.debug "options = " + options.inspect
100
- @logger.debug "params.payload = " + params[:payload].inspect
101
- token = params["token"]
102
- @logger.debug "token = "+ token.inspect
87
+ @logger.debug "params = " + params.inspect
88
+ @logger.debug "options = " + options.inspect
89
+ @logger.debug "params.payload = " + params[:payload].inspect
90
+ @logger.debug "token = "+ token.inspect
103
91
  begin
104
- # here's what get() does:
105
- #parse_response RestClient.get(append_params(url(method), add_params(method, params)), headers), options
106
- parse_response(RestClient.post(url(method)+"?oauth="+token, add_params(method, params).to_json, headers.merge!({:content_type=>'application/json', :accept => "json"})), options)
107
- # was , add_params(method, params).to_json, headers.merge!({:content_type=>'application/json'})), options)
108
- #ClientHelper.run_http(host, access_key, secret_key, :post, method, nil, params)
109
- rescue RestClient::Exception => ex
92
+ url = url(method) + "?oauth=" + token
93
+ @logger.debug 'post url=' + url
94
+ parse_response(RestClient.post(url, add_params(method, params).to_json, headers.merge!({:content_type=>'application/json', :accept => "json"})), options)
95
+ rescue RestClient::Exception => ex
96
+ @logger.warn("Exception in post! #{ex.message}")
97
+ @logger.warn(ex.backtrace.join("\n"))
110
98
  process_ex(ex)
111
99
  end
112
100
  end
@@ -115,8 +103,7 @@ module SimpleWorker
115
103
  def put(method, body, options={})
116
104
  begin
117
105
  parse_response RestClient.put(url(method), add_params(method, body).to_json, headers), options
118
- #ClientHelper.run_http(host, access_key, secret_key, :put, method, body, nil)
119
- rescue RestClient::Exception => ex
106
+ rescue RestClient::Exception => ex
120
107
  process_ex(ex)
121
108
  end
122
109
  end
@@ -130,9 +117,7 @@ module SimpleWorker
130
117
  end
131
118
 
132
119
  def add_params(command_path, hash)
133
- v = version || "2.0"
134
- ts = SimpleWorker::Api::Signatures.generate_timestamp(Time.now.gmtime)
135
- extra_params = {'version'=>v, 'timestamp' => ts, 'oauth' => token}
120
+ extra_params = {'oauth' => token}
136
121
  hash.merge!(extra_params)
137
122
  end
138
123
 
@@ -378,34 +378,17 @@ module SimpleWorker
378
378
  end
379
379
  end
380
380
 
381
- # puts 'upload_if_needed ' + self.class.name
382
- # Todo, watch for this file changing or something so we can reupload (if in dev env)
383
- unless uploaded?
381
+ if !uploaded?
384
382
  unmerged = self.class.instance_variable_get(:@unmerged)
385
383
  merged_gems = self.class.instance_variable_get(:@merged_gems)
386
384
  merged_mailers = self.class.instance_variable_get(:@merged_mailers)
387
385
  merged_folders = self.class.instance_variable_get(:@merged_folders)
388
- # puts 'merged1=' + merged.inspect
389
-
390
386
  merged, rfile, subclass = SimpleWorker::Base.extract_superclasses_merges(self, merged)
391
- #if SimpleWorker.config.auto_merge
392
- # puts "Auto merge Enabled"
393
- #if SimpleWorker.config.models
394
- # SimpleWorker.config.models.each do |m|
395
- # merged[m] = m
396
- # end
397
- #end
398
387
  merged_mailers = merged_mailers.merge(SimpleWorker.config.mailers) if SimpleWorker.config.mailers
399
- #SimpleWorker.config.gems.each do |gem|
400
- # merged_gems[gem[:name]] = gem
401
- #end
402
- #end
403
388
  unless merged_gems.size == 0
404
389
  merged_gems = gems_to_merge(merged_gems)
405
- #merged_gems.uniq!
406
390
  end
407
- #merged.uniq!
408
- # merged_mailers.uniq!
391
+
409
392
  options_for_upload = {:merge=>merged, :unmerge=>unmerged, :merged_gems=>merged_gems, :merged_mailers=>merged_mailers, :merged_folders=>merged_folders}
410
393
  options_for_upload.merge!(options)
411
394
  SimpleWorker.service.upload(rfile, subclass.name, options_for_upload)
@@ -414,7 +397,6 @@ module SimpleWorker
414
397
  SimpleWorker.logger.debug 'Already uploaded for ' + self.class.name
415
398
  end
416
399
 
417
-
418
400
  after_upload
419
401
  end
420
402
 
@@ -26,7 +26,8 @@ module SimpleWorker
26
26
  :merged,
27
27
  :unmerged,
28
28
  :merged_gems,
29
- :unmerged_gems
29
+ :unmerged_gems,
30
+ :force_upload
30
31
 
31
32
 
32
33
  def initialize
@@ -157,6 +158,7 @@ module SimpleWorker
157
158
  config_data['mailer'] = self.mailer if self.mailer
158
159
  config_data['global_attributes'] = self.global_attributes if self.global_attributes
159
160
  config_data['host'] = self.host if self.host
161
+ config_data['port'] = self.port if self.port
160
162
  config_data
161
163
  end
162
164
 
@@ -175,8 +175,8 @@ module SimpleWorker
175
175
  end
176
176
 
177
177
  def add_sw_params(hash_to_send)
178
- hash_to_send["token"] = self.config['token']
179
- hash_to_send["project_id"] = self.config['project_id']
178
+ hash_to_send["token"] = self.config.token
179
+ hash_to_send["project_id"] = self.config.project_id
180
180
  hash_to_send["api_version"] = SimpleWorker.api_version
181
181
  end
182
182
  end
@@ -65,7 +65,7 @@ def init_worker_service_for_runner(job_data)
65
65
  config.project_id = sw_config['project_id']
66
66
  #puts 'Setting host to ' + host.inspect
67
67
  config.host = sw_config['host'] if sw_config['host']
68
- config.host = sw_config['port'] if sw_config['port']
68
+ config.port = sw_config['port'] if sw_config['port']
69
69
  db_config = sw_config['database']
70
70
  if db_config
71
71
  config.database = db_config
@@ -24,6 +24,7 @@ module SimpleWorker
24
24
  options[:logger] = SimpleWorker.logger
25
25
  super("api2.simpleworker.com", token, options)
26
26
  self.host = self.config.host if self.config && self.config.host
27
+ self.config.merge_gem('simple_worker')#automerge simple worker gem
27
28
  SimpleWorker.logger.info 'SimpleWorker initialized.'
28
29
  SimpleWorker.logger.debug ' host = ' + self.host.inspect
29
30
  end
@@ -46,7 +47,7 @@ module SimpleWorker
46
47
  # Check for code changes.
47
48
  md5 = Digest::MD5.hexdigest(File.read(filename))
48
49
  new_code = false
49
- if md5 != existing_md5
50
+ if self.config.force_upload || md5 != existing_md5
50
51
  SimpleWorker.logger.info "Uploading #{class_name}, code modified."
51
52
  File.open(md5_f, 'w') { |f| f.write(md5) }
52
53
  new_code = true
@@ -90,7 +91,7 @@ module SimpleWorker
90
91
  SimpleWorker.logger.debug 'gems found=' + gems.inspect
91
92
  gems = gems.select { |g| g.version.version==gem_info[:version] } if gem_info[:version]
92
93
  if !gems.empty?
93
- gem = gems.first
94
+ gem = gems.last
94
95
  gem.full_gem_path
95
96
  else
96
97
  return nil
@@ -420,7 +421,7 @@ end
420
421
  hash_to_send["class_name"] = class_name unless hash_to_send["class_name"]
421
422
  hash_to_send["name"] = class_name unless hash_to_send["name"]
422
423
  uri = project_url_prefix(get_project_id(options)) + "jobs"
423
- SimpleWorker.logger.info 'queue_raw , uri = ' + uri
424
+ SimpleWorker.logger.debug 'queue_raw , uri = ' + uri
424
425
  ret = post(uri, hash_to_send)
425
426
  ret
426
427
  end
@@ -523,10 +524,10 @@ end
523
524
  ret
524
525
  end
525
526
 
526
- # data is a hash, should include 'percent' and 'message'
527
- def set_progress(task_id, data)
528
- data={"data"=>data, "task_id"=>task_id}
529
- post("task/setstatus", data)
527
+ # data is a hash, should include 'percent' and 'msg'
528
+ def set_progress(task_id, options={})
529
+ #data={"data"=>data, "task_id"=>task_id}
530
+ post("#{project_url_prefix(get_project_id(options))}jobs/#{task_id}/progress", options)
530
531
  end
531
532
 
532
533
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simple_worker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 2.0.0.beta.5
5
+ version: 2.0.0.beta.6
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-09-30 00:00:00 Z
13
+ date: 2011-10-01 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: zip