iron_worker 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,117 @@
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
@@ -0,0 +1,11 @@
1
+ # UsedInWorker can be included in classes that you are merging in order to get some of the IronWorker features into that class.
2
+ # For instance, you can use the log() method and it will be logged to the IronWorker logs.
3
+
4
+ module IronWorker
5
+ module UsedInWorker
6
+
7
+ def log(str)
8
+ puts str.to_s
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module IronWorker
2
+
3
+ module Utils
4
+
5
+ def self.ends_with?(s, suffix)
6
+ suffix = suffix.to_s
7
+ s[-suffix.length, suffix.length] == suffix
8
+ end
9
+ end
10
+
11
+ end
data/rails/init.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iron_worker
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Travis Reeder
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: zip
16
+ requirement: &22128360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *22128360
25
+ - !ruby/object:Gem::Dependency
26
+ name: rest-client
27
+ requirement: &22127820 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *22127820
36
+ - !ruby/object:Gem::Dependency
37
+ name: zip
38
+ requirement: &22127060 !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: *22127060
47
+ - !ruby/object:Gem::Dependency
48
+ name: rest-client
49
+ requirement: &22125520 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *22125520
58
+ description: The official IronWorker gem for IronWorker by Iron.io. http://www.iron.io
59
+ email: travis@iron.io
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - README.markdown
64
+ files:
65
+ - VERSION.yml
66
+ - lib/generators/iron_worker/iron_worker_generator.rb
67
+ - lib/iron_worker.rb
68
+ - lib/iron_worker/api.rb
69
+ - lib/iron_worker/base.rb
70
+ - lib/iron_worker/config.rb
71
+ - lib/iron_worker/rails2_init.rb
72
+ - lib/iron_worker/railtie.rb
73
+ - lib/iron_worker/server/overrides.rb
74
+ - lib/iron_worker/server/runner.rb
75
+ - lib/iron_worker/service.rb
76
+ - lib/iron_worker/uber_client.rb
77
+ - lib/iron_worker/used_in_worker.rb
78
+ - lib/iron_worker/utils.rb
79
+ - rails/init.rb
80
+ - README.markdown
81
+ homepage: http://www.iron.io
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '1.9'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.11
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: The official IronWorker gem for IronWorker by Iron.io. http://www.iron.io
105
+ test_files: []