kinetic_sdk 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +7 -0
  2. data/GettingStarted.md +64 -0
  3. data/README.md +383 -0
  4. data/bin/console +12 -0
  5. data/bin/setup +8 -0
  6. data/gems/kontena-websocket-client-0.1.1/Gemfile +4 -0
  7. data/gems/kontena-websocket-client-0.1.1/LICENSE +190 -0
  8. data/gems/kontena-websocket-client-0.1.1/README.md +138 -0
  9. data/gems/kontena-websocket-client-0.1.1/Rakefile +6 -0
  10. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-client.rb +45 -0
  11. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-em.rb +66 -0
  12. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.rb +161 -0
  13. data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.sh +17 -0
  14. data/gems/kontena-websocket-client-0.1.1/benchmark/websocket-echo-server.go +207 -0
  15. data/gems/kontena-websocket-client-0.1.1/examples/websocket-echo-client.rb +80 -0
  16. data/gems/kontena-websocket-client-0.1.1/kontena-websocket-client.gemspec +24 -0
  17. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/connection.rb +119 -0
  18. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/version.rb +13 -0
  19. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client.rb +848 -0
  20. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/error.rb +81 -0
  21. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/logging.rb +55 -0
  22. data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/openssl_patch.rb +10 -0
  23. data/gems/kontena-websocket-client-0.1.1/lib/kontena-websocket-client.rb +15 -0
  24. data/gems/mime-types-3.1/Code-of-Conduct.rdoc +74 -0
  25. data/gems/mime-types-3.1/Contributing.rdoc +130 -0
  26. data/gems/mime-types-3.1/History.rdoc +658 -0
  27. data/gems/mime-types-3.1/Licence.rdoc +25 -0
  28. data/gems/mime-types-3.1/Manifest.txt +31 -0
  29. data/gems/mime-types-3.1/README.rdoc +202 -0
  30. data/gems/mime-types-3.1/Rakefile +254 -0
  31. data/gems/mime-types-3.1/lib/mime/type/columnar.rb +55 -0
  32. data/gems/mime-types-3.1/lib/mime/type.rb +573 -0
  33. data/gems/mime-types-3.1/lib/mime/types/_columnar.rb +135 -0
  34. data/gems/mime-types-3.1/lib/mime/types/cache.rb +56 -0
  35. data/gems/mime-types-3.1/lib/mime/types/columnar.rb +1 -0
  36. data/gems/mime-types-3.1/lib/mime/types/container.rb +30 -0
  37. data/gems/mime-types-3.1/lib/mime/types/deprecations.rb +32 -0
  38. data/gems/mime-types-3.1/lib/mime/types/full.rb +17 -0
  39. data/gems/mime-types-3.1/lib/mime/types/loader.rb +148 -0
  40. data/gems/mime-types-3.1/lib/mime/types/logger.rb +37 -0
  41. data/gems/mime-types-3.1/lib/mime/types/registry.rb +81 -0
  42. data/gems/mime-types-3.1/lib/mime/types.rb +228 -0
  43. data/gems/mime-types-3.1/lib/mime-types.rb +1 -0
  44. data/gems/mime-types-3.1/test/bad-fixtures/malformed +9 -0
  45. data/gems/mime-types-3.1/test/fixture/json.json +1 -0
  46. data/gems/mime-types-3.1/test/fixture/old-data +9 -0
  47. data/gems/mime-types-3.1/test/fixture/yaml.yaml +55 -0
  48. data/gems/mime-types-3.1/test/minitest_helper.rb +13 -0
  49. data/gems/mime-types-3.1/test/test_mime_type.rb +603 -0
  50. data/gems/mime-types-3.1/test/test_mime_types.rb +161 -0
  51. data/gems/mime-types-3.1/test/test_mime_types_cache.rb +109 -0
  52. data/gems/mime-types-3.1/test/test_mime_types_class.rb +155 -0
  53. data/gems/mime-types-3.1/test/test_mime_types_lazy.rb +43 -0
  54. data/gems/mime-types-3.1/test/test_mime_types_loader.rb +32 -0
  55. data/gems/mime-types-data-3.2016.0521/Code-of-Conduct.md +75 -0
  56. data/gems/mime-types-data-3.2016.0521/Contributing.md +157 -0
  57. data/gems/mime-types-data-3.2016.0521/History.md +351 -0
  58. data/gems/mime-types-data-3.2016.0521/Licence.md +25 -0
  59. data/gems/mime-types-data-3.2016.0521/Manifest.txt +18 -0
  60. data/gems/mime-types-data-3.2016.0521/README.md +61 -0
  61. data/gems/mime-types-data-3.2016.0521/Rakefile +80 -0
  62. data/gems/mime-types-data-3.2016.0521/data/mime-types.json +1 -0
  63. data/gems/mime-types-data-3.2016.0521/data/mime.content_type.column +1964 -0
  64. data/gems/mime-types-data-3.2016.0521/data/mime.docs.column +1964 -0
  65. data/gems/mime-types-data-3.2016.0521/data/mime.encoding.column +1964 -0
  66. data/gems/mime-types-data-3.2016.0521/data/mime.flags.column +1964 -0
  67. data/gems/mime-types-data-3.2016.0521/data/mime.friendly.column +1964 -0
  68. data/gems/mime-types-data-3.2016.0521/data/mime.pext.column +1964 -0
  69. data/gems/mime-types-data-3.2016.0521/data/mime.use_instead.column +1964 -0
  70. data/gems/mime-types-data-3.2016.0521/data/mime.xrefs.column +1964 -0
  71. data/gems/mime-types-data-3.2016.0521/lib/mime/types/data.rb +21 -0
  72. data/gems/mime-types-data-3.2016.0521/lib/mime-types-data.rb +3 -0
  73. data/gems/multipart-post-2.0.0/Gemfile +14 -0
  74. data/gems/multipart-post-2.0.0/History.txt +60 -0
  75. data/gems/multipart-post-2.0.0/Manifest.txt +9 -0
  76. data/gems/multipart-post-2.0.0/README.md +77 -0
  77. data/gems/multipart-post-2.0.0/Rakefile +9 -0
  78. data/gems/multipart-post-2.0.0/lib/composite_io.rb +108 -0
  79. data/gems/multipart-post-2.0.0/lib/multipart_post.rb +9 -0
  80. data/gems/multipart-post-2.0.0/lib/multipartable.rb +29 -0
  81. data/gems/multipart-post-2.0.0/lib/net/http/post/multipart.rb +27 -0
  82. data/gems/multipart-post-2.0.0/lib/parts.rb +96 -0
  83. data/gems/multipart-post-2.0.0/multipart-post.gemspec +22 -0
  84. data/gems/multipart-post-2.0.0/test/multibyte.txt +1 -0
  85. data/gems/multipart-post-2.0.0/test/net/http/post/test_multipart.rb +110 -0
  86. data/gems/multipart-post-2.0.0/test/test_composite_io.rb +115 -0
  87. data/gems/multipart-post-2.0.0/test/test_parts.rb +86 -0
  88. data/gems/parallel-1.12.1/MIT-LICENSE.txt +20 -0
  89. data/gems/parallel-1.12.1/lib/parallel/processor_count.rb +93 -0
  90. data/gems/parallel-1.12.1/lib/parallel/version.rb +3 -0
  91. data/gems/parallel-1.12.1/lib/parallel.rb +500 -0
  92. data/gems/ruby-progressbar-1.9.0/LICENSE.txt +19 -0
  93. data/gems/ruby-progressbar-1.9.0/README.md +38 -0
  94. data/gems/ruby-progressbar-1.9.0/Rakefile +2 -0
  95. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/base.rb +183 -0
  96. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/length.rb +99 -0
  97. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/running_average.rb +9 -0
  98. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/bar.rb +96 -0
  99. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/percentage.rb +29 -0
  100. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/rate.rb +43 -0
  101. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/time.rb +107 -0
  102. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/title.rb +13 -0
  103. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components.rb +5 -0
  104. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/errors/invalid_progress_error.rb +4 -0
  105. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/formatter.rb +27 -0
  106. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/molecule.rb +59 -0
  107. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/string.rb +36 -0
  108. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format.rb +3 -0
  109. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/output.rb +68 -0
  110. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/non_tty.rb +47 -0
  111. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/null.rb +33 -0
  112. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/tty.rb +32 -0
  113. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/progress.rb +118 -0
  114. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements/enumerator.rb +25 -0
  115. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements.rb +1 -0
  116. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/throttle.rb +25 -0
  117. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/time.rb +30 -0
  118. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb +72 -0
  119. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/version.rb +3 -0
  120. data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar.rb +18 -0
  121. data/gems/slugify-1.0.7/README +18 -0
  122. data/gems/slugify-1.0.7/lib/slugify.rb +1012 -0
  123. data/gems/slugify-1.0.7/lib/slugify_string.rb +11 -0
  124. data/gems/slugify-1.0.7/tests/slugify_test.rb +116 -0
  125. data/gems/slugify-1.0.7/tests/string_slugify_test.rb +23 -0
  126. data/gems/websocket-driver-0.6.5/CHANGELOG.md +123 -0
  127. data/gems/websocket-driver-0.6.5/LICENSE.md +22 -0
  128. data/gems/websocket-driver-0.6.5/README.md +369 -0
  129. data/gems/websocket-driver-0.6.5/examples/tcp_server.rb +28 -0
  130. data/gems/websocket-driver-0.6.5/ext/websocket-driver/Makefile +264 -0
  131. data/gems/websocket-driver-0.6.5/ext/websocket-driver/WebsocketMaskService.java +55 -0
  132. data/gems/websocket-driver-0.6.5/ext/websocket-driver/extconf.rb +4 -0
  133. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.bundle +0 -0
  134. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.c +41 -0
  135. data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.o +0 -0
  136. data/gems/websocket-driver-0.6.5/lib/websocket/driver/client.rb +140 -0
  137. data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft75.rb +102 -0
  138. data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft76.rb +96 -0
  139. data/gems/websocket-driver-0.6.5/lib/websocket/driver/event_emitter.rb +54 -0
  140. data/gems/websocket-driver-0.6.5/lib/websocket/driver/headers.rb +45 -0
  141. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/frame.rb +20 -0
  142. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/message.rb +31 -0
  143. data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi.rb +406 -0
  144. data/gems/websocket-driver-0.6.5/lib/websocket/driver/proxy.rb +68 -0
  145. data/gems/websocket-driver-0.6.5/lib/websocket/driver/server.rb +80 -0
  146. data/gems/websocket-driver-0.6.5/lib/websocket/driver/stream_reader.rb +55 -0
  147. data/gems/websocket-driver-0.6.5/lib/websocket/driver.rb +199 -0
  148. data/gems/websocket-driver-0.6.5/lib/websocket/http/headers.rb +112 -0
  149. data/gems/websocket-driver-0.6.5/lib/websocket/http/request.rb +45 -0
  150. data/gems/websocket-driver-0.6.5/lib/websocket/http/response.rb +29 -0
  151. data/gems/websocket-driver-0.6.5/lib/websocket/http.rb +15 -0
  152. data/gems/websocket-driver-0.6.5/lib/websocket/mask.rb +14 -0
  153. data/gems/websocket-driver-0.6.5/lib/websocket/websocket_mask.rb +2 -0
  154. data/gems/websocket-driver-0.6.5/lib/websocket_mask.bundle +0 -0
  155. data/gems/websocket-driver-0.6.5-java/CHANGELOG.md +123 -0
  156. data/gems/websocket-driver-0.6.5-java/LICENSE.md +22 -0
  157. data/gems/websocket-driver-0.6.5-java/README.md +369 -0
  158. data/gems/websocket-driver-0.6.5-java/examples/tcp_server.rb +28 -0
  159. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/WebsocketMaskService.java +55 -0
  160. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/extconf.rb +4 -0
  161. data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/websocket_mask.c +41 -0
  162. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/client.rb +140 -0
  163. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft75.rb +102 -0
  164. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft76.rb +96 -0
  165. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/event_emitter.rb +54 -0
  166. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/headers.rb +45 -0
  167. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/frame.rb +20 -0
  168. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/message.rb +31 -0
  169. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi.rb +406 -0
  170. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/proxy.rb +68 -0
  171. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/server.rb +80 -0
  172. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/stream_reader.rb +55 -0
  173. data/gems/websocket-driver-0.6.5-java/lib/websocket/driver.rb +199 -0
  174. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/headers.rb +112 -0
  175. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/request.rb +45 -0
  176. data/gems/websocket-driver-0.6.5-java/lib/websocket/http/response.rb +29 -0
  177. data/gems/websocket-driver-0.6.5-java/lib/websocket/http.rb +15 -0
  178. data/gems/websocket-driver-0.6.5-java/lib/websocket/mask.rb +14 -0
  179. data/gems/websocket-driver-0.6.5-java/lib/websocket/websocket_mask.rb +2 -0
  180. data/gems/websocket-driver-0.6.5-java/lib/websocket_mask.jar +0 -0
  181. data/gems/websocket-extensions-0.1.3/CHANGELOG.md +15 -0
  182. data/gems/websocket-extensions-0.1.3/LICENSE.md +20 -0
  183. data/gems/websocket-extensions-0.1.3/README.md +313 -0
  184. data/gems/websocket-extensions-0.1.3/lib/websocket/extensions/parser.rb +111 -0
  185. data/gems/websocket-extensions-0.1.3/lib/websocket/extensions.rb +181 -0
  186. data/lib/kinetic-sdk.rb +1 -0
  187. data/lib/kinetic_sdk/bridgehub/bridgehub-sdk.rb +80 -0
  188. data/lib/kinetic_sdk/bridgehub/lib/access_keys.rb +67 -0
  189. data/lib/kinetic_sdk/bridgehub/lib/bridge.rb +69 -0
  190. data/lib/kinetic_sdk/discussions/discussions-sdk.rb +165 -0
  191. data/lib/kinetic_sdk/discussions/lib/discussions.rb +107 -0
  192. data/lib/kinetic_sdk/discussions/lib/invitations.rb +120 -0
  193. data/lib/kinetic_sdk/discussions/lib/messages.rb +190 -0
  194. data/lib/kinetic_sdk/discussions/lib/meta.rb +14 -0
  195. data/lib/kinetic_sdk/discussions/lib/participants.rb +64 -0
  196. data/lib/kinetic_sdk/discussions/lib/related_items.rb +54 -0
  197. data/lib/kinetic_sdk/discussions/lib/websockets.rb +96 -0
  198. data/lib/kinetic_sdk/filehub/filehub-sdk.rb +80 -0
  199. data/lib/kinetic_sdk/filehub/lib/access_keys.rb +67 -0
  200. data/lib/kinetic_sdk/filehub/lib/filestores.rb +67 -0
  201. data/lib/kinetic_sdk/request_ce/lib/attribute_definitions.rb +153 -0
  202. data/lib/kinetic_sdk/request_ce/lib/bridges.rb +66 -0
  203. data/lib/kinetic_sdk/request_ce/lib/categories.rb +34 -0
  204. data/lib/kinetic_sdk/request_ce/lib/datastore_form.rb +110 -0
  205. data/lib/kinetic_sdk/request_ce/lib/datastore_submissions.rb +157 -0
  206. data/lib/kinetic_sdk/request_ce/lib/form.rb +99 -0
  207. data/lib/kinetic_sdk/request_ce/lib/form_types.rb +51 -0
  208. data/lib/kinetic_sdk/request_ce/lib/jwt.rb +55 -0
  209. data/lib/kinetic_sdk/request_ce/lib/kapp.rb +93 -0
  210. data/lib/kinetic_sdk/request_ce/lib/meta.rb +14 -0
  211. data/lib/kinetic_sdk/request_ce/lib/oauth.rb +37 -0
  212. data/lib/kinetic_sdk/request_ce/lib/security_policy_definitions.rb +157 -0
  213. data/lib/kinetic_sdk/request_ce/lib/space.rb +89 -0
  214. data/lib/kinetic_sdk/request_ce/lib/submissions.rb +215 -0
  215. data/lib/kinetic_sdk/request_ce/lib/system_api.rb +69 -0
  216. data/lib/kinetic_sdk/request_ce/lib/teams.rb +113 -0
  217. data/lib/kinetic_sdk/request_ce/lib/users.rb +245 -0
  218. data/lib/kinetic_sdk/request_ce/lib/webhook_jobs.rb +142 -0
  219. data/lib/kinetic_sdk/request_ce/lib/webhooks.rb +192 -0
  220. data/lib/kinetic_sdk/request_ce/request-ce-sdk.rb +153 -0
  221. data/lib/kinetic_sdk/task/lib/access_keys.rb +94 -0
  222. data/lib/kinetic_sdk/task/lib/categories.rb +190 -0
  223. data/lib/kinetic_sdk/task/lib/config.rb +202 -0
  224. data/lib/kinetic_sdk/task/lib/engine.rb +42 -0
  225. data/lib/kinetic_sdk/task/lib/environment.rb +14 -0
  226. data/lib/kinetic_sdk/task/lib/errors.rb +165 -0
  227. data/lib/kinetic_sdk/task/lib/groups.rb +112 -0
  228. data/lib/kinetic_sdk/task/lib/handlers.rb +105 -0
  229. data/lib/kinetic_sdk/task/lib/health.rb +28 -0
  230. data/lib/kinetic_sdk/task/lib/license.rb +52 -0
  231. data/lib/kinetic_sdk/task/lib/policy_rules.rb +166 -0
  232. data/lib/kinetic_sdk/task/lib/setup.rb +56 -0
  233. data/lib/kinetic_sdk/task/lib/sources.rb +134 -0
  234. data/lib/kinetic_sdk/task/lib/tasks.rb +17 -0
  235. data/lib/kinetic_sdk/task/lib/trees.rb +274 -0
  236. data/lib/kinetic_sdk/task/lib/users.rb +75 -0
  237. data/lib/kinetic_sdk/task/task-sdk.rb +92 -0
  238. data/lib/kinetic_sdk/utils/kinetic-http-headers.rb +150 -0
  239. data/lib/kinetic_sdk/utils/kinetic-http-response.rb +75 -0
  240. data/lib/kinetic_sdk/utils/kinetic-http.rb +552 -0
  241. data/lib/kinetic_sdk/utils/logger.rb +70 -0
  242. data/lib/kinetic_sdk/utils/random.rb +30 -0
  243. data/lib/kinetic_sdk/version.rb +7 -0
  244. data/lib/kinetic_sdk.rb +57 -0
  245. metadata +414 -0
@@ -0,0 +1,500 @@
1
+ require 'rbconfig'
2
+ require 'parallel/version'
3
+ require 'parallel/processor_count'
4
+
5
+ module Parallel
6
+ extend Parallel::ProcessorCount
7
+
8
+ class DeadWorker < StandardError
9
+ end
10
+
11
+ class Break < StandardError
12
+ end
13
+
14
+ class Kill < StandardError
15
+ end
16
+
17
+ class UndumpableException < StandardError
18
+ attr_reader :backtrace
19
+ def initialize(original)
20
+ super "#{original.class}: #{original.message}"
21
+ @backtrace = original.backtrace
22
+ end
23
+ end
24
+
25
+ Stop = Object.new
26
+
27
+ class ExceptionWrapper
28
+ attr_reader :exception
29
+ def initialize(exception)
30
+ # Remove the bindings stack added by the better_errors gem,
31
+ # because it cannot be marshalled
32
+ if exception.instance_variable_defined? :@__better_errors_bindings_stack
33
+ exception.send :remove_instance_variable, :@__better_errors_bindings_stack
34
+ end
35
+
36
+ @exception =
37
+ begin
38
+ Marshal.dump(exception) && exception
39
+ rescue
40
+ UndumpableException.new(exception)
41
+ end
42
+ end
43
+ end
44
+
45
+ class Worker
46
+ attr_reader :pid, :read, :write
47
+ attr_accessor :thread
48
+ def initialize(read, write, pid)
49
+ @read, @write, @pid = read, write, pid
50
+ end
51
+
52
+ def stop
53
+ close_pipes
54
+ wait # if it goes zombie, rather wait here to be able to debug
55
+ end
56
+
57
+ # might be passed to started_processes and simultaneously closed by another thread
58
+ # when running in isolation mode, so we have to check if it is closed before closing
59
+ def close_pipes
60
+ read.close unless read.closed?
61
+ write.close unless write.closed?
62
+ end
63
+
64
+ def work(data)
65
+ begin
66
+ Marshal.dump(data, write)
67
+ rescue Errno::EPIPE
68
+ raise DeadWorker
69
+ end
70
+
71
+ result = begin
72
+ Marshal.load(read)
73
+ rescue EOFError
74
+ raise DeadWorker
75
+ end
76
+ raise result.exception if ExceptionWrapper === result
77
+ result
78
+ end
79
+
80
+ private
81
+
82
+ def wait
83
+ Process.wait(pid)
84
+ rescue Interrupt
85
+ # process died
86
+ end
87
+ end
88
+
89
+ class JobFactory
90
+ def initialize(source, mutex)
91
+ @lambda = (source.respond_to?(:call) && source) || queue_wrapper(source)
92
+ @source = source.to_a unless @lambda # turn Range and other Enumerable-s into an Array
93
+ @mutex = mutex
94
+ @index = -1
95
+ @stopped = false
96
+ end
97
+
98
+ def next
99
+ if producer?
100
+ # - index and item stay in sync
101
+ # - do not call lambda after it has returned Stop
102
+ item, index = @mutex.synchronize do
103
+ return if @stopped
104
+ item = @lambda.call
105
+ @stopped = (item == Parallel::Stop)
106
+ return if @stopped
107
+ [item, @index += 1]
108
+ end
109
+ else
110
+ index = @mutex.synchronize { @index += 1 }
111
+ return if index >= size
112
+ item = @source[index]
113
+ end
114
+ [item, index]
115
+ end
116
+
117
+ def size
118
+ if producer?
119
+ Float::INFINITY
120
+ else
121
+ @source.size
122
+ end
123
+ end
124
+
125
+ # generate item that is sent to workers
126
+ # just index is faster + less likely to blow up with unserializable errors
127
+ def pack(item, index)
128
+ producer? ? [item, index] : index
129
+ end
130
+
131
+ # unpack item that is sent to workers
132
+ def unpack(data)
133
+ producer? ? data : [@source[data], data]
134
+ end
135
+
136
+ private
137
+
138
+ def producer?
139
+ @lambda
140
+ end
141
+
142
+ def queue_wrapper(array)
143
+ array.respond_to?(:num_waiting) && array.respond_to?(:pop) && lambda { array.pop(false) }
144
+ end
145
+ end
146
+
147
+ class UserInterruptHandler
148
+ INTERRUPT_SIGNAL = :SIGINT
149
+
150
+ class << self
151
+ # kill all these pids or threads if user presses Ctrl+c
152
+ def kill_on_ctrl_c(pids, options)
153
+ @to_be_killed ||= []
154
+ old_interrupt = nil
155
+ signal = options.fetch(:interrupt_signal, INTERRUPT_SIGNAL)
156
+
157
+ if @to_be_killed.empty?
158
+ old_interrupt = trap_interrupt(signal) do
159
+ $stderr.puts 'Parallel execution interrupted, exiting ...'
160
+ @to_be_killed.flatten.each { |pid| kill(pid) }
161
+ end
162
+ end
163
+
164
+ @to_be_killed << pids
165
+
166
+ yield
167
+ ensure
168
+ @to_be_killed.pop # do not kill pids that could be used for new processes
169
+ restore_interrupt(old_interrupt, signal) if @to_be_killed.empty?
170
+ end
171
+
172
+ def kill(thing)
173
+ Process.kill(:KILL, thing)
174
+ rescue Errno::ESRCH
175
+ # some linux systems already automatically killed the children at this point
176
+ # so we just ignore them not being there
177
+ end
178
+
179
+ private
180
+
181
+ def trap_interrupt(signal)
182
+ old = Signal.trap signal, 'IGNORE'
183
+
184
+ Signal.trap signal do
185
+ yield
186
+ if !old || old == "DEFAULT"
187
+ raise Interrupt
188
+ else
189
+ old.call
190
+ end
191
+ end
192
+
193
+ old
194
+ end
195
+
196
+ def restore_interrupt(old, signal)
197
+ Signal.trap signal, old
198
+ end
199
+ end
200
+ end
201
+
202
+ class << self
203
+ def in_threads(options={:count => 2})
204
+ count, _ = extract_count_from_options(options)
205
+ Array.new(count) do |i|
206
+ Thread.new { yield(i) }
207
+ end.map!(&:value)
208
+ end
209
+
210
+ def in_processes(options = {}, &block)
211
+ count, options = extract_count_from_options(options)
212
+ count ||= processor_count
213
+ map(0...count, options.merge(:in_processes => count), &block)
214
+ end
215
+
216
+ def each(array, options={}, &block)
217
+ map(array, options.merge(:preserve_results => false), &block)
218
+ end
219
+
220
+ def any?(*args, &block)
221
+ raise "You must provide a block when calling #any?" if block.nil?
222
+ !each(*args) { |*a| raise Parallel::Kill if block.call(*a) }
223
+ end
224
+
225
+ def all?(*args, &block)
226
+ raise "You must provide a block when calling #all?" if block.nil?
227
+ !!each(*args) { |*a| raise Parallel::Kill unless block.call(*a) }
228
+ end
229
+
230
+ def each_with_index(array, options={}, &block)
231
+ each(array, options.merge(:with_index => true), &block)
232
+ end
233
+
234
+ def map(source, options = {}, &block)
235
+ options[:mutex] = Mutex.new
236
+
237
+ if RUBY_PLATFORM =~ /java/ and not options[:in_processes]
238
+ method = :in_threads
239
+ size = options[method] || processor_count
240
+ elsif options[:in_threads]
241
+ method = :in_threads
242
+ size = options[method]
243
+ else
244
+ method = :in_processes
245
+ if Process.respond_to?(:fork)
246
+ size = options[method] || processor_count
247
+ else
248
+ warn "Process.fork is not supported by this Ruby"
249
+ size = 0
250
+ end
251
+ end
252
+
253
+ job_factory = JobFactory.new(source, options[:mutex])
254
+ size = [job_factory.size, size].min
255
+
256
+ options[:return_results] = (options[:preserve_results] != false || !!options[:finish])
257
+ add_progress_bar!(job_factory, options)
258
+
259
+ results = if size == 0
260
+ work_direct(job_factory, options, &block)
261
+ elsif method == :in_threads
262
+ work_in_threads(job_factory, options.merge(:count => size), &block)
263
+ else
264
+ work_in_processes(job_factory, options.merge(:count => size), &block)
265
+ end
266
+ if results
267
+ options[:return_results] ? results : source
268
+ end
269
+ end
270
+
271
+ def map_with_index(array, options={}, &block)
272
+ map(array, options.merge(:with_index => true), &block)
273
+ end
274
+
275
+ def worker_number
276
+ Thread.current[:parallel_worker_number]
277
+ end
278
+
279
+ def worker_number=(worker_num)
280
+ Thread.current[:parallel_worker_number] = worker_num
281
+ end
282
+
283
+ private
284
+
285
+ def add_progress_bar!(job_factory, options)
286
+ if progress_options = options[:progress]
287
+ raise "Progressbar can only be used with array like items" if job_factory.size == Float::INFINITY
288
+ require 'ruby-progressbar'
289
+
290
+ if progress_options == true
291
+ progress_options = { title: "Progress" }
292
+ elsif progress_options.respond_to? :to_str
293
+ progress_options = { title: progress_options.to_str }
294
+ end
295
+
296
+ progress_options = {
297
+ total: job_factory.size,
298
+ format: '%t |%E | %B | %a'
299
+ }.merge(progress_options)
300
+
301
+ progress = ProgressBar.create(progress_options)
302
+ old_finish = options[:finish]
303
+ options[:finish] = lambda do |item, i, result|
304
+ old_finish.call(item, i, result) if old_finish
305
+ progress.increment
306
+ end
307
+ end
308
+ end
309
+
310
+ def work_direct(job_factory, options, &block)
311
+ self.worker_number = 0
312
+ results = []
313
+ exception = nil
314
+ begin
315
+ while set = job_factory.next
316
+ item, index = set
317
+ results << with_instrumentation(item, index, options) do
318
+ call_with_index(item, index, options, &block)
319
+ end
320
+ end
321
+ rescue
322
+ exception = $!
323
+ end
324
+ handle_exception(exception, results)
325
+ ensure
326
+ self.worker_number = nil
327
+ end
328
+
329
+ def work_in_threads(job_factory, options, &block)
330
+ raise "interrupt_signal is no longer supported for threads" if options[:interrupt_signal]
331
+ results = []
332
+ results_mutex = Mutex.new # arrays are not thread-safe on jRuby
333
+ exception = nil
334
+
335
+ in_threads(options) do |worker_num|
336
+ self.worker_number = worker_num
337
+ # as long as there are more jobs, work on one of them
338
+ while !exception && set = job_factory.next
339
+ begin
340
+ item, index = set
341
+ result = with_instrumentation item, index, options do
342
+ call_with_index(item, index, options, &block)
343
+ end
344
+ results_mutex.synchronize { results[index] = result }
345
+ rescue
346
+ exception = $!
347
+ end
348
+ end
349
+ end
350
+
351
+ handle_exception(exception, results)
352
+ end
353
+
354
+ def work_in_processes(job_factory, options, &blk)
355
+ workers = if options[:isolation]
356
+ [] # we create workers per job and not beforehand
357
+ else
358
+ create_workers(job_factory, options, &blk)
359
+ end
360
+ results = []
361
+ results_mutex = Mutex.new # arrays are not thread-safe
362
+ exception = nil
363
+
364
+ UserInterruptHandler.kill_on_ctrl_c(workers.map(&:pid), options) do
365
+ in_threads(options) do |i|
366
+ worker = workers[i]
367
+
368
+ begin
369
+ loop do
370
+ break if exception
371
+ item, index = job_factory.next
372
+ break unless index
373
+
374
+ if options[:isolation]
375
+ worker = replace_worker(job_factory, workers, i, options, blk)
376
+ end
377
+
378
+ worker.thread = Thread.current
379
+
380
+ begin
381
+ result = with_instrumentation item, index, options do
382
+ worker.work(job_factory.pack(item, index))
383
+ end
384
+ results_mutex.synchronize { results[index] = result } # arrays are not threads safe on jRuby
385
+ rescue
386
+ exception = $!
387
+ if Parallel::Kill === exception
388
+ (workers - [worker]).each do |w|
389
+ w.thread.kill unless w.thread.nil?
390
+ UserInterruptHandler.kill(w.pid)
391
+ end
392
+ end
393
+ end
394
+ end
395
+ ensure
396
+ worker.stop if worker
397
+ end
398
+ end
399
+ end
400
+
401
+ handle_exception(exception, results)
402
+ end
403
+
404
+ def replace_worker(job_factory, workers, i, options, blk)
405
+ options[:mutex].synchronize do
406
+ # old worker is no longer used ... stop it
407
+ worker = workers[i]
408
+ worker.stop if worker
409
+
410
+ # create a new replacement worker
411
+ running = workers - [worker]
412
+ workers[i] = worker(job_factory, options.merge(started_workers: running, worker_number: i), &blk)
413
+ end
414
+ end
415
+
416
+ def create_workers(job_factory, options, &block)
417
+ workers = []
418
+ Array.new(options[:count]).each_with_index do |_, i|
419
+ workers << worker(job_factory, options.merge(started_workers: workers, worker_number: i), &block)
420
+ end
421
+ workers
422
+ end
423
+
424
+ def worker(job_factory, options, &block)
425
+ child_read, parent_write = IO.pipe
426
+ parent_read, child_write = IO.pipe
427
+
428
+ pid = Process.fork do
429
+ self.worker_number = options[:worker_number]
430
+
431
+ begin
432
+ options.delete(:started_workers).each(&:close_pipes)
433
+
434
+ parent_write.close
435
+ parent_read.close
436
+
437
+ process_incoming_jobs(child_read, child_write, job_factory, options, &block)
438
+ ensure
439
+ child_read.close
440
+ child_write.close
441
+ end
442
+ end
443
+
444
+ child_read.close
445
+ child_write.close
446
+
447
+ Worker.new(parent_read, parent_write, pid)
448
+ end
449
+
450
+ def process_incoming_jobs(read, write, job_factory, options, &block)
451
+ until read.eof?
452
+ data = Marshal.load(read)
453
+ item, index = job_factory.unpack(data)
454
+ result = begin
455
+ call_with_index(item, index, options, &block)
456
+ rescue
457
+ ExceptionWrapper.new($!)
458
+ end
459
+ Marshal.dump(result, write)
460
+ end
461
+ end
462
+
463
+ def handle_exception(exception, results)
464
+ return nil if [Parallel::Break, Parallel::Kill].include? exception.class
465
+ raise exception if exception
466
+ results
467
+ end
468
+
469
+ # options is either a Integer or a Hash with :count
470
+ def extract_count_from_options(options)
471
+ if options.is_a?(Hash)
472
+ count = options[:count]
473
+ else
474
+ count = options
475
+ options = {}
476
+ end
477
+ [count, options]
478
+ end
479
+
480
+ def call_with_index(item, index, options, &block)
481
+ args = [item]
482
+ args << index if options[:with_index]
483
+ if options[:return_results]
484
+ block.call(*args)
485
+ else
486
+ block.call(*args)
487
+ nil # avoid GC overhead of passing large results around
488
+ end
489
+ end
490
+
491
+ def with_instrumentation(item, index, options)
492
+ on_start = options[:start]
493
+ on_finish = options[:finish]
494
+ options[:mutex].synchronize { on_start.call(item, index) } if on_start
495
+ result = yield
496
+ options[:mutex].synchronize { on_finish.call(item, index, result) } if on_finish
497
+ result unless options[:preserve_results] == false
498
+ end
499
+ end
500
+ end
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010-2016 The Kompanee, Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ Ruby/ProgressBar
2
+ ================================
3
+ [![Gem Version](https://img.shields.io/gem/v/ruby-progressbar.svg)](https://rubygems.org/gems/ruby-progressbar) ![Rubygems Rank Overall](https://img.shields.io/gem/rt/ruby-progressbar.svg) ![Rubygems Rank Daily](https://img.shields.io/gem/rd/ruby-progressbar.svg) ![Rubygems Downloads](https://img.shields.io/gem/dv/ruby-progressbar/stable.svg) [![Build Status](https://img.shields.io/travis/jfelchner/ruby-progressbar/master.svg)](http://travis-ci.org/jfelchner/ruby-progressbar) [![Code Climate](https://codeclimate.com/github/jfelchner/ruby-progressbar.svg)](https://codeclimate.com/github/jfelchner/ruby-progressbar) [![Code Climate](https://codeclimate.com/github/jfelchner/ruby-progressbar/coverage.svg)](https://codeclimate.com/github/jfelchner/ruby-progressbar)
4
+
5
+ <img src="https://kompanee-public-assets.s3.amazonaws.com/readmes/ruby-progressbar-cage.png" align="right" />
6
+
7
+ The **ultimate** text progress bar library for Ruby! It'll **SMASH YOU OVER THE HEAD** with a **PURE RUSH** of progress bar excitement!
8
+
9
+ Don't miss out on what all the kids are talking about! If you want everyone to know that your gem or app can survive _in the cage_ then YOU WANT **RUBY-PROGRESSBAR**!
10
+
11
+ <br><br><br>
12
+
13
+ Full Reference
14
+ --------------------------------
15
+
16
+ There's gotten to be too much awesome to pack into one page. Visit the [wiki](https://github.com/jfelchner/ruby-progressbar/wiki) for the full documentation.
17
+
18
+ Here's a [quick link](https://github.com/jfelchner/ruby-progressbar/wiki/Basic-Usage) to the 'Basic Usage' section.
19
+
20
+ Issues
21
+ --------------------------------
22
+
23
+ If you have problems, please create a [Github issue](https://github.com/jfelchner/ruby-progressbar/issues).
24
+
25
+ Credits
26
+ --------------------------------
27
+
28
+ ![The Kompanee](https://kompanee-public-assets.s3.amazonaws.com/readmes/kompanee-horizontal-black.png)
29
+
30
+ ruby-progressbar is maintained by [The Kompanee, Ltd.](http://www.thekompanee.com)
31
+
32
+ The names and logos for The Kompanee are trademarks of The Kompanee, Ltd.
33
+
34
+ License
35
+ --------------------------------
36
+
37
+ ruby-progressbar 1.0 is Copyright &copy; 2011-2018 The Kompanee. It is free software, and may be redistributed under the terms specified in the LICENSE file.
38
+ ruby-progressbar 0.9.0 is Copyright &copy; 2008 [Satoru Takabayashi](http://0xcc.net)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'