Skip to content

Commit 0fcd526

Browse files
authored
Merge pull request #412 from envato/save_image_threads_config
Add config option to set threads for saving images
2 parents 0c8d1a4 + a628269 commit 0fcd526

File tree

8 files changed

+28
-1
lines changed

8 files changed

+28
-1
lines changed

lib/wraith/save_images.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def run_command(command)
7676
end
7777

7878
def parallel_task(jobs)
79-
Parallel.each(jobs, :in_threads => 8) do |_label, _path, width, url, filename, selector, global_before_capture, path_before_capture|
79+
Parallel.each(jobs, :in_threads => wraith.save_image_threads) do |_label, _path, width, url, filename, selector, global_before_capture, path_before_capture|
8080
begin
8181
if meta.engine == "chrome"
8282
capture_image_selenium(width, url, filename, selector, global_before_capture, path_before_capture)

lib/wraith/wraith.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,8 @@ def verbose
211211
# @TODO - also add a `--verbose` CLI flag which overrides whatever you have set in the config
212212
@config["verbose"] || false
213213
end
214+
215+
def save_image_threads
216+
(@config["save_image_threads"] || 8).to_i
217+
end
214218
end

spec/config_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
it "include compare label" do
7777
expect(wraith.paths).to eq("home" => "/", "uk_index" => "/uk")
7878
end
79+
80+
it "include save image threads" do
81+
expect(wraith.save_image_threads).to eq(7)
82+
end
7983
end
8084

8185
describe "different ways of initialising browser engine" do

spec/configs/test_config--casper.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ paths:
2828

2929
#Amount of fuzz ImageMagick will use
3030
fuzz: '20%'
31+
32+
# Number of threads used when saving images
33+
save_image_threads: 7

spec/configs/test_config--phantom.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ paths:
3232

3333
#Amount of fuzz ImageMagick will use
3434
fuzz: '20%'
35+
36+
37+
# Number of threads used when saving images
38+
save_image_threads: 7

templates/configs/capture.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ gallery:
5959
# diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
6060
# Note: different screen widths are always grouped together.
6161
mode: diffs_first
62+
63+
# (optional) Set the number of threads to use when saving images. Raising this value can improve performance, but very high
64+
# values can lead to server connection issues. Set to around 1.5 the available CPU cores for best performance. Default: 8
65+
save_image_threads: 8

templates/configs/history.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,7 @@ highlight_color: red
7979

8080
# (optional) Parameters to pass to Phantom/Casper command line. Default: '--ignore-ssl-errors=true --ssl-protocol=tlsv1'
8181
phantomjs_options: ''
82+
83+
# (optional) Set the number of threads to use when saving images. Raising this value can improve performance, but very high
84+
# values can lead to server connection issues. Set to around 1.5 the available CPU cores for best performance. Default: 8
85+
save_image_threads: 8

templates/configs/spider.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ directory: 'shots'
5858
# diffs_first - all paths (with or without a difference) are shown, sorted by difference size (largest first)
5959
# diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
6060
mode: diffs_first
61+
62+
# (optional) Set the number of threads to use when saving images. Raising this value can improve performance, but very high
63+
# values can lead to server connection issues. Set to around 1.5 the available CPU cores for best performance. Default: 8
64+
save_image_threads: 8

0 commit comments

Comments
 (0)