rake-opt-parallel 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjI4NmI1OWE0Y2JhY2FiY2NmMDYwMGZiYTQxYzJlOTU2MTdjMDllNQ==
5
+ data.tar.gz: !binary |-
6
+ YjQ2NGIwZjllMjI5MDRhNGQ2MWUxYWQ5OGVkMjFkNjNkYmRjNDczNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MmU4ZTJiMjVlMzNhN2Q0MjFkMGI4NmNlOWMxYTU5MzJkMWU1NDdlZGUwYzE4
10
+ ZmZjZjBkMmNjODgwMWJkNWIwODk1NGZjYWI2ZTllOTVlMGI2M2RhZDNkMzk1
11
+ MWRjNTRjODZiNDY2NzIyYzNjOWE0OTNkNDkzNTliMzc4YTJiMjA=
12
+ data.tar.gz: !binary |-
13
+ NGZmM2RmNTMwMDJjZDU5MzhjMjQ5NzNkYTkzMjcyNWM1ZjUzN2Q5YTFlMjJl
14
+ MDM3YzczNTc3YzFjODI3YWFhNGViZGZkOWFiZjQzM2QwMDJlZWM0NzA4NGY0
15
+ NTI4OWQ5ZWY3ZTgzMWM0MTE1YzFhZGEyNzczNTUxM2RmNTAwOGU=
@@ -0,0 +1,56 @@
1
+ require 'active_support/all'
2
+ require 'hashie'
3
+
4
+ # Add some parallel iterators to Enumerable
5
+ module Enumerable
6
+ def parallel_each(options={}, &block)
7
+ parallel_map(options, &block)
8
+ return self.each {}
9
+ end
10
+
11
+
12
+ def parallel_map(options={}, &block)
13
+ # Convert options hash to a mash
14
+ options = ::Hashie::Mash.new(options)
15
+
16
+ use_seperate_pool = options.force.present? || options.unlimited
17
+ execution_ids = options[:execution_ids]
18
+ if execution_ids
19
+ raise 'The execution_ids array must be same length as Enum Object' if execution_ids.size != self.count
20
+ else
21
+ execution_ids = Array.new(self.size)
22
+ end
23
+
24
+ if use_seperate_pool
25
+ thread_count = options.unlimited ? self.size : options.force
26
+ # Create a seperate thread pool
27
+ thread_pool = Rake::ThreadPool.new(thread_count-1)
28
+ else
29
+ # Otherwise, use the existing thread pool
30
+ thread_pool = Rake.application.thread_pool
31
+ end
32
+
33
+ # Convert them to Promises to be fulfuilled
34
+ promises = self.to_a.map do |item|
35
+ thread_pool.future(item, &execution_id_wrapper(execution_ids.shift, &block))
36
+ end
37
+
38
+ # Fulfill all promises
39
+ promises.reverse_each { |f| f.value }
40
+ return promises.map { |f| f.value }
41
+ end
42
+
43
+ def execution_id_wrapper(id, &block)
44
+ # Have the block set an execution_id on launch
45
+ new_block = lambda do |*args|
46
+ if id
47
+ Thread.current.execution_id = id
48
+ else
49
+ Thread.current.reset_execution_id
50
+ end
51
+ output = block.call(*args) if block
52
+ Thread.current.clear_execution_id
53
+ return output
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,21 @@
1
+ # Thread class override
2
+ # Adds execution_id helpers
3
+ class ::Thread
4
+ EXECUTION_ID_LENGTH = 16
5
+
6
+ def execution_id
7
+ return self['execution_id']
8
+ end
9
+
10
+ def execution_id=(manual_id)
11
+ self['execution_id'] = manual_id
12
+ end
13
+
14
+ def clear_execution_id
15
+ self['execution_id'] = nil
16
+ end
17
+
18
+ def reset_execution_id
19
+ self['execution_id'] = rand(36**EXECUTION_ID_LENGTH).to_s(36)
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'patches/enumerable.rb'
2
+ require_relative 'patches/thread.rb'
@@ -0,0 +1 @@
1
+ require_relative 'parallel/patches.rb'
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-opt-parallel
3
+ version: !ruby/object:Gem::Version
4
+ version: !binary |-
5
+ MC4xLjA=
6
+ platform: ruby
7
+ authors:
8
+ - Jon San Miguel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-03-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: !binary |-
21
+ NC4xLjA=
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: !binary |-
29
+ NC4xLjA=
30
+ - !ruby/object:Gem::Dependency
31
+ name: hashie
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: !binary |-
37
+ Mi4xLjE=
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: !binary |-
45
+ Mi4xLjE=
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: !binary |-
53
+ MTAuMy4y
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: !binary |-
61
+ MTAuMy4y
62
+ description: ! 'Provides: 1. parallel_each and parallel_map to Enum types 2. Tracking
63
+ of promise lineage'
64
+ email: jon.sanmiguel@optimizely.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/rake/opt/parallel.rb
70
+ - lib/rake/opt/parallel/patches.rb
71
+ - lib/rake/opt/parallel/patches/enumerable.rb
72
+ - lib/rake/opt/parallel/patches/thread.rb
73
+ homepage: http://rubygems.org/gems/rake-opt-parallel
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.8
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Enhanced rake parallelism
97
+ test_files: []