iron_worker 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 2
3
- :minor: 1
4
- :patch: 1
3
+ :minor: 2
4
+ :patch: 0
5
5
  :build:
@@ -1,5 +1,4 @@
1
- require 'rest_client'
2
- require_relative 'uber_client'
1
+ require 'rest'
3
2
 
4
3
  module IronWorker
5
4
 
@@ -54,12 +53,15 @@ module IronWorker
54
53
  @version = options[:version]
55
54
  #@logger = options[:logger]
56
55
 
57
- @base_url = "#{@scheme}://#{@host}:#{@port}/#{@version}"
56
+ reset_base_url
58
57
 
59
- @uber_client = Uber::Client.new
58
+ @uber_client = Rest::Client.new
60
59
 
61
60
  end
62
61
 
62
+ def reset_base_url
63
+ @base_url = "#{@scheme}://#{@host}:#{@port}/#{@version}"
64
+ end
63
65
 
64
66
  def base_url
65
67
  @base_url
@@ -77,13 +79,13 @@ module IronWorker
77
79
  end
78
80
 
79
81
 
80
- def common_req_hash
81
- {
82
- :headers=>{"Content-Type" => 'application/json',
83
- "Authorization"=>"OAuth #{@token}",
84
- "User-Agent"=>"IronWorker Ruby Client"}
85
- }
86
- end
82
+ def common_req_hash
83
+ {
84
+ :headers=>{"Content-Type" => 'application/json',
85
+ "Authorization"=>"OAuth #{@token}",
86
+ "User-Agent"=>"IronWorker Ruby Client"}
87
+ }
88
+ end
87
89
 
88
90
  def process_ex(ex)
89
91
  logger.error "EX #{ex.class.name}: #{ex.message}"
@@ -25,7 +25,9 @@ module IronWorker
25
25
  super("worker-aws-us-east-1.iron.io", token, options)
26
26
  self.host = self.config.host if self.config && self.config.host
27
27
  # automerge simple worker gem and dependenices
28
+ self.config.merge_gem('zip')
28
29
  self.config.merge_gem('rest-client')
30
+ self.config.merge_gem('rest')
29
31
  self.config.merge_gem('iron_worker')
30
32
  IronWorker.logger.info 'IronWorker initialized.'
31
33
  IronWorker.logger.debug ' host = ' + self.host.inspect
@@ -499,21 +501,21 @@ end
499
501
 
500
502
  def get_codes(options={})
501
503
  hash_to_send = {}
502
- uri = "projects/" + get_project_id(options) + "/codes/"
504
+ uri = "projects/" + get_project_id(options) + "/codes"
503
505
  ret = get(uri, hash_to_send)
504
506
  ret
505
507
  end
506
508
 
507
509
  def get_schedules(options={})
508
510
  hash_to_send = {}
509
- uri = "projects/" + get_project_id(options) + "/schedules/"
511
+ uri = "projects/" + get_project_id(options) + "/schedules"
510
512
  ret = get(uri, hash_to_send)
511
513
  ret
512
514
  end
513
515
 
514
516
  def get_jobs(options={})
515
517
  hash_to_send = {}
516
- uri = "projects/" + get_project_id(options) + "/tasks/"
518
+ uri = "projects/" + get_project_id(options) + "/tasks"
517
519
  ret = get(uri, hash_to_send)
518
520
  ret
519
521
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-05 00:00:00.000000000 Z
12
+ date: 2011-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: zip
16
- requirement: &23155260 !ruby/object:Gem::Requirement
16
+ requirement: &9516660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *23155260
24
+ version_requirements: *9516660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &23154320 !ruby/object:Gem::Requirement
27
+ requirement: &9548900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *23154320
35
+ version_requirements: *9548900
36
+ - !ruby/object:Gem::Dependency
37
+ name: rest
38
+ requirement: &9545520 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *9545520
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: zip
38
- requirement: &23153100 !ruby/object:Gem::Requirement
49
+ requirement: &9544720 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,21 @@ dependencies:
43
54
  version: '0'
44
55
  type: :runtime
45
56
  prerelease: false
46
- version_requirements: *23153100
57
+ version_requirements: *9544720
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rest-client
49
- requirement: &23152180 !ruby/object:Gem::Requirement
60
+ requirement: &9567580 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *9567580
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest
71
+ requirement: &9564080 !ruby/object:Gem::Requirement
50
72
  none: false
51
73
  requirements:
52
74
  - - ! '>='
@@ -54,7 +76,7 @@ dependencies:
54
76
  version: '0'
55
77
  type: :runtime
56
78
  prerelease: false
57
- version_requirements: *23152180
79
+ version_requirements: *9564080
58
80
  description: The official IronWorker gem for IronWorker by Iron.io. http://www.iron.io
59
81
  email: travis@iron.io
60
82
  executables: []
@@ -73,7 +95,6 @@ files:
73
95
  - lib/iron_worker/server/overrides.rb
74
96
  - lib/iron_worker/server/runner.rb
75
97
  - lib/iron_worker/service.rb
76
- - lib/iron_worker/uber_client.rb
77
98
  - lib/iron_worker/used_in_worker.rb
78
99
  - lib/iron_worker/utils.rb
79
100
  - rails/init.rb
@@ -1,117 +0,0 @@
1
- # This is a simple wrapper that can use different http clients depending on what's installed.
2
- # The purpose of this is so that users who can't install binaries easily (like windoze users) can have fallbacks that work.
3
-
4
-
5
- module Uber
6
- def self.gem=(g)
7
- @gem = g
8
- end
9
-
10
- def self.gem
11
- @gem
12
- end
13
-
14
- begin
15
- require 'typhoeus'
16
- Uber.gem = :typhoeus
17
- rescue LoadError => ex
18
- puts "Could not load typhoeus. #{ex.class.name}: #{ex.message}. Falling back to rest-client. Please install 'typhoeus' gem for best performance."
19
- require 'rest_client'
20
- Uber.gem = :rest_client
21
- end
22
-
23
- class RestClientResponseWrapper
24
- def initialize(response)
25
- @response = response
26
- end
27
-
28
- def code
29
- @response.code
30
- end
31
-
32
- def body
33
- @response.body
34
- end
35
-
36
- end
37
-
38
- class ClientError < StandardError
39
-
40
- end
41
-
42
- class RestClientExceptionWrapper < ClientError
43
- def initialize(ex)
44
- super(ex.message)
45
- @ex = ex
46
- end
47
- end
48
-
49
- class TimeoutError < ClientError
50
- def initialize(msg=nil)
51
- msg ||= "HTTP Request Timed out."
52
- super(msg)
53
- end
54
- end
55
-
56
- class TyphoeusTimeoutError < TimeoutError
57
- def initialize(response)
58
- msg ||= "HTTP Request Timed out. Curl code: #{response.curl_return_code}. Curl error msg: #{response.curl_error_message}."
59
- super(msg)
60
- end
61
- end
62
-
63
- class Client
64
-
65
- def initialize
66
-
67
- end
68
-
69
- def get(url, req_hash={})
70
- if Uber.gem == :typhoeus
71
- req_hash[:connect_timeout] = 5000
72
- req_hash[:timeout] ||= 10000
73
- # puts "REQ_HASH=" + req_hash.inspect
74
- response = Typhoeus::Request.get(url, req_hash)
75
- #p response
76
- if response.timed_out?
77
- raise TyphoeusTimeoutError.new(response)
78
- end
79
- else
80
- begin
81
- headers = req_hash[:headers] || {}
82
- r2 = RestClient.get(url, req_hash.merge(headers))
83
- response = RestClientResponseWrapper.new(r2)
84
- # todo: make generic exception
85
- rescue RestClient::Exception => ex
86
- raise RestClientExceptionWrapper.new(ex)
87
- end
88
- end
89
- response
90
- end
91
-
92
- def post(url, req_hash={})
93
- if Uber.gem == :typhoeus
94
- # todo: should change this timeout to longer if it's for posting file
95
- req_hash[:connect_timeout] = 5000
96
- req_hash[:timeout] ||= 10000
97
- # puts "REQ_HASH=" + req_hash.inspect
98
- response = Typhoeus::Request.post(url, req_hash)
99
- #p response
100
- if response.timed_out?
101
- raise TyphoeusTimeoutError.new(response)
102
- end
103
- else
104
- begin
105
- headers = req_hash[:headers] || {}
106
- r2 = RestClient.post(url, req_hash[:body], headers)
107
- response = RestClientResponseWrapper.new(r2)
108
- # todo: make generic exception
109
- rescue RestClient::Exception => ex
110
- raise RestClientExceptionWrapper(ex)
111
- end
112
- end
113
- response
114
- end
115
-
116
- end
117
- end