Skip to content

Commit 0d9906f

Browse files
committed
feat!: add support for transcoding status checks
BREAKING CHANGE: - The `FFMPEG::Transcoding::Status#success?` method now checks whether all output files have been created or not. This behaviour can be disabled by setting the `checks` keyword argument on the transcoder to an empty array (or whatever checks you wish to perform). - Transcoding retries now consider the transcoding status checks when deciding whether to retry the process or not.
1 parent 6b0310d commit 0d9906f

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

lib/ffmpeg/transcoder.rb

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,31 @@ class Transcoder
2727
class Status < FFMPEG::Status
2828
attr_reader :paths
2929

30-
def initialize(paths)
30+
def initialize(paths, checks: %i[exist?])
3131
@paths = paths
32+
@checks = checks
3233
super()
3334
end
3435

36+
# Returns true if the transcoding process was successful.
37+
# It returns true if the process exited with a zero exit status
38+
# and all checks passed.
39+
#
40+
# @return [Boolean] True if the transcoding process was successful, false otherwise.
41+
def success?
42+
return false unless super
43+
44+
@checks.all? do |check|
45+
if check.is_a?(Symbol) && respond_to?(check)
46+
send(check)
47+
elsif check.respond_to?(:call)
48+
check.call(self)
49+
else
50+
raise ArgumentError, "Unknown check format #{check.class}, expected #{Symbol} or #{Proc}"
51+
end
52+
end
53+
end
54+
3555
# Returns the media files associated with the transcoding process.
3656
#
3757
# @param ffprobe_args [Array<String>] The arguments to pass to ffprobe.
@@ -43,15 +63,23 @@ def media(*ffprobe_args, load: true, autoload: true)
4363
Media.new(path, *ffprobe_args, load: load, autoload: autoload)
4464
end
4565
end
66+
67+
# Returns true if all output paths exist.
68+
#
69+
# @return [Boolean] True if all output paths exist, false otherwise.
70+
def exist?
71+
@paths.all? { |path| File.exist?(path) }
72+
end
4673
end
4774

48-
attr_reader :name, :metadata, :presets, :reporters, :timeout
75+
attr_reader :name, :metadata, :presets, :reporters, :checks, :retries, :timeout
4976

5077
def initialize(
5178
name: nil,
5279
metadata: nil,
5380
presets: [],
5481
reporters: nil,
82+
checks: %i[exist?],
5583
retries: nil,
5684
timeout: nil,
5785
&compose_inargs
@@ -60,8 +88,9 @@ def initialize(
6088
@metadata = metadata
6189
@presets = presets
6290
@reporters = reporters
63-
@timeout = timeout
91+
@checks = checks
6492
@retries = retries&.abs || 0
93+
@timeout = timeout
6594
@compose_inargs = compose_inargs
6695
end
6796

@@ -102,7 +131,7 @@ def process(media, output_path, &)
102131
inargs:,
103132
reporters:,
104133
timeout:,
105-
status: Status.new(output_paths),
134+
status: Status.new(output_paths, checks:),
106135
&
107136
)
108137

0 commit comments

Comments
 (0)