davinci_threader 1.0.0 → 2.0.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 +5 -5
- data/lib/davinci_threader/main.rb +67 -10
- data/lib/davinci_threader/version.rb +1 -1
- metadata +31 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e559ab8c3238af1b99fe848efc0d99b7013e8b1fe8bcd78717fb1e0933d0beb6
|
4
|
+
data.tar.gz: cb695b3ab7e189d0f0556ef968e02aadd2329fd882389c23981f6ae06cbfb67b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2727dd3ccd7438d5b4c28a43b7d959a4918ac331de16e0c21c197ea21c174c017548d97aa54ff68fb614914ee28162642d0553631a65d00499dbf7474a9cdea6
|
7
|
+
data.tar.gz: 38a0775392777694711199b034260e7c45a00da7c9c7439dfa4b90e3d68c36deb479e483a877513094ecba367f96d75d089c6b8098b15407cf3f5d0546879976
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'colorize'
|
2
|
+
require 'awesome_print'
|
2
3
|
require 'active_support/core_ext/numeric/time'
|
3
4
|
|
4
5
|
|
@@ -23,6 +24,17 @@ module DavinciThreader
|
|
23
24
|
attr_accessor :extras
|
24
25
|
attr_accessor :max_threads
|
25
26
|
attr_accessor :asynchronous
|
27
|
+
def show_output=(_on)
|
28
|
+
@show_output = _on
|
29
|
+
if !_on
|
30
|
+
@monitor.try(:exit)
|
31
|
+
@monitor = nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def show_output
|
35
|
+
@show_output
|
36
|
+
end
|
37
|
+
attr_accessor :synchronous_items
|
26
38
|
attr_reader :thread_count
|
27
39
|
# ======================================================
|
28
40
|
|
@@ -39,30 +51,36 @@ module DavinciThreader
|
|
39
51
|
self.extras = []
|
40
52
|
self.max_threads = 10
|
41
53
|
self.asynchronous = true
|
54
|
+
self.show_output = true
|
55
|
+
self.synchronous_items = []
|
42
56
|
@threads = []
|
43
57
|
@thread_count = 0
|
44
58
|
|
45
59
|
@monitor = Thread.new do
|
46
60
|
while self.log
|
47
|
-
printout if @start_time
|
61
|
+
printout if self.show_output && @start_time
|
48
62
|
sleep 0.1
|
49
63
|
end
|
50
64
|
end
|
51
65
|
|
52
|
-
yield
|
66
|
+
yield(self)
|
53
67
|
|
54
|
-
@threads.each
|
55
|
-
|
56
|
-
@monitor.exit
|
57
|
-
|
68
|
+
@threads.each(&:join)
|
69
|
+
@threads_finished_at = Time.now
|
70
|
+
@monitor.try(:exit)
|
71
|
+
print "\n" if self.show_output && @synchronous
|
72
|
+
@synchronous.try(:join)
|
73
|
+
@synchronous.try(:exit)
|
74
|
+
puts "\n-> Done!".light_green if self.show_output && self.log
|
58
75
|
|
59
76
|
rescue Interrupt
|
60
77
|
|
61
|
-
@monitor.exit
|
78
|
+
@monitor.try(:exit)
|
62
79
|
|
63
80
|
begin
|
64
81
|
puts "\n-> Waiting for remaining threads to finish...".yellow
|
65
82
|
@threads.each(&:join)
|
83
|
+
@synchronous.try(:exit)
|
66
84
|
puts "-> Exited!".yellow
|
67
85
|
rescue Interrupt
|
68
86
|
force_exit
|
@@ -73,6 +91,27 @@ module DavinciThreader
|
|
73
91
|
end
|
74
92
|
# ======================================================
|
75
93
|
|
94
|
+
# Synchronous Action
|
95
|
+
# ======================================================
|
96
|
+
def synchronous_action
|
97
|
+
@synchronous = Thread.new do
|
98
|
+
begin
|
99
|
+
while !@threads_finished_at || self.synchronous_items.count > 0
|
100
|
+
if self.synchronous_items.count == 0
|
101
|
+
sleep(1)
|
102
|
+
else
|
103
|
+
yield(self.synchronous_items.first)
|
104
|
+
self.synchronous_items.shift
|
105
|
+
self.synchronous_printout if self.show_output && @threads_finished_at
|
106
|
+
end
|
107
|
+
end
|
108
|
+
rescue => e
|
109
|
+
ap e.message
|
110
|
+
ap e.backtrace
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
# ======================================================
|
76
115
|
|
77
116
|
# Make Thread
|
78
117
|
# ======================================================
|
@@ -82,7 +121,7 @@ module DavinciThreader
|
|
82
121
|
|
83
122
|
if !self.asynchronous
|
84
123
|
yield(*args)
|
85
|
-
self.printout
|
124
|
+
self.printout if self.show_output
|
86
125
|
return
|
87
126
|
end
|
88
127
|
|
@@ -119,24 +158,41 @@ module DavinciThreader
|
|
119
158
|
# ======================================================
|
120
159
|
def printout
|
121
160
|
|
122
|
-
c = Time.now - @start_time
|
161
|
+
c = (@threads_finished_at || Time.now) - @start_time
|
123
162
|
output = []
|
124
163
|
if self.asynchronous
|
125
164
|
output << "#{"#{@rpm.to_i}/MIN".cyan}"
|
126
165
|
output << "#{Time.at(c.to_f).utc.strftime("%H:%M:%S")}"
|
127
166
|
if self.completed > 100
|
128
167
|
actual_rate = (self.completed.to_f / c.to_f) * 60.0
|
129
|
-
output << "#{actual_rate
|
168
|
+
output << "#{'%.2f' % actual_rate}/MIN".light_green
|
130
169
|
output << "#{Time.at(((self.total-self.completed).to_f / actual_rate) * 60.0).utc.strftime("%H:%M:%S")}".light_green
|
131
170
|
end
|
132
171
|
end
|
133
172
|
output << "#{self.completed}/#{self.total} (#{self.successful.to_s.light_green} <--> #{self.errors.to_s.light_red})"
|
173
|
+
output << "Synchronous: #{"#{self.synchronous_items.count}".purple}" if @synchronous
|
134
174
|
output += self.extras
|
135
175
|
print "\r#{output.join(" :: ".yellow)} "
|
136
176
|
|
137
177
|
end
|
138
178
|
# ======================================================
|
139
179
|
|
180
|
+
# Synchronous Printout
|
181
|
+
# ======================================================
|
182
|
+
def synchronous_printout
|
183
|
+
elapsed_time = Time.now - @threads_finished_at
|
184
|
+
@synchronous_remaining = self.synchronous_items.count
|
185
|
+
@synchronous_start_count ||= @synchronous_remaining
|
186
|
+
@synchronous_completed = @synchronous_start_count - @synchronous_remaining
|
187
|
+
if @synchronous_completed > 0
|
188
|
+
@synchronous_rate_per_second = @synchronous_completed.to_f / elapsed_time
|
189
|
+
seconds_remaining = @synchronous_remaining.to_f / @synchronous_rate_per_second
|
190
|
+
@synchronous_nice_time = Time.at(seconds_remaining).utc.strftime("%H:%M:%S")
|
191
|
+
end
|
192
|
+
print "\r#{"Synchronous".purple} -> Remaining: #{"#{@synchronous_remaining}".light_yellow} :: Completed: #{"#{@synchronous_completed}".light_green} :: Rate: #{"#{'%.2f' % ((@synchronous_rate_per_second || 0) * 60.0)}".light_cyan} :: #{"#{@synchronous_nice_time}".light_green} "
|
193
|
+
end
|
194
|
+
# ======================================================
|
195
|
+
|
140
196
|
# Increment Methods
|
141
197
|
# ======================================================
|
142
198
|
def success
|
@@ -156,6 +212,7 @@ module DavinciThreader
|
|
156
212
|
@monitor.try(:exit)
|
157
213
|
puts "\n-> Killing remaining threads...".light_red
|
158
214
|
@threads.each(&:exit)
|
215
|
+
@synchronous.try(:exit)
|
159
216
|
puts "-> Forced Exit!".light_red
|
160
217
|
end
|
161
218
|
# ======================================================
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: davinci_threader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- onlyexcellence
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.9'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: activesupport
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: 0.8.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: awesome_print
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.8'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.8'
|
69
97
|
description: Useful for APIs that limit requests
|
70
98
|
email:
|
71
99
|
- will@wambl.com
|
@@ -100,8 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
128
|
- !ruby/object:Gem::Version
|
101
129
|
version: '0'
|
102
130
|
requirements: []
|
103
|
-
|
104
|
-
rubygems_version: 2.6.13
|
131
|
+
rubygems_version: 3.0.6
|
105
132
|
signing_key:
|
106
133
|
specification_version: 4
|
107
134
|
summary: Thread Throttling
|