forked from toy/image_optim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
timeout option to restrict maximum time spent on every image
The original commit discourse/image_optim@8bf3c0e, see discussion in resolved PRs. Resolves toy#21, resolves toy#148, resolves toy#149, resolves toy#162, resolves toy#184, resolves toy#189. Co-authored-by: Blake Erickson <[email protected]>
- Loading branch information
Showing
28 changed files
with
349 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
class ImageOptim | ||
# Use Process.clock_gettime if available to get time more fitting to calculate elapsed time | ||
module ElapsedTime | ||
CLOCK_NAME = %w[ | ||
CLOCK_UPTIME_RAW | ||
CLOCK_UPTIME | ||
CLOCK_MONOTONIC_RAW | ||
CLOCK_MONOTONIC | ||
CLOCK_REALTIME | ||
].find{ |name| Process.const_defined?(name) } | ||
|
||
CLOCK_ID = CLOCK_NAME && Process.const_get(CLOCK_NAME) | ||
|
||
module_function | ||
|
||
def now | ||
if CLOCK_ID | ||
Process.clock_gettime(CLOCK_ID) | ||
else | ||
Time.now.to_f | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class ImageOptim | ||
class Error < StandardError; end | ||
|
||
module Errors | ||
class TimeoutExceeded < Error; end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'image_optim/elapsed_time' | ||
|
||
class ImageOptim | ||
# Hold start time and timeout | ||
class Timer | ||
include ElapsedTime | ||
|
||
def initialize(seconds) | ||
@start = now | ||
@seconds = seconds | ||
end | ||
|
||
def elapsed | ||
now - @start | ||
end | ||
|
||
def left | ||
@seconds - elapsed | ||
end | ||
|
||
alias_method :to_f, :left | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.