diff --git a/config/config.php b/config/config.php index beef9b6..5fb5bd6 100644 --- a/config/config.php +++ b/config/config.php @@ -55,4 +55,13 @@ * migration as part of the package. */ 'track_media_conversions' => true, + + /** + * If track_media_conversions is set to true, you may specify the events you would like to fire/track. + * By default, it will track all status updates. + * + * Read more about MediaConvert conversion statuses here: + * https://docs.aws.amazon.com/mediaconvert/latest/ug/mediaconvert_cwe_events.html + */ + 'statuses_to_track' => ['complete', 'error', 'new_warning', 'progressing', 'input_information', 'queue_hop'], ]; diff --git a/src/Events/ConversionHasCompleted.php b/src/Events/ConversionHasCompleted.php index 90397e4..20c3253 100644 --- a/src/Events/ConversionHasCompleted.php +++ b/src/Events/ConversionHasCompleted.php @@ -22,7 +22,10 @@ public function __construct($message) { $this->message = $message; - if (config('media-convert.track_media_conversions')) { + if ( + config('media-convert.track_media_conversions') + && in_array('complete', config('media-convert.events_to_track')) + ) { MediaConversion::createActivity($message); } } diff --git a/src/Events/ConversionHasError.php b/src/Events/ConversionHasError.php index 5f128f4..38b07de 100644 --- a/src/Events/ConversionHasError.php +++ b/src/Events/ConversionHasError.php @@ -22,7 +22,10 @@ public function __construct($message) { $this->message = $message; - if (config('media-convert.track_media_conversions')) { + if ( + config('media-convert.track_media_conversions') + && in_array('error', config('media-convert.events_to_track')) + ) { MediaConversion::createActivity($message); } } diff --git a/src/Events/ConversionHasInputInformation.php b/src/Events/ConversionHasInputInformation.php index adf0f35..741d9b6 100644 --- a/src/Events/ConversionHasInputInformation.php +++ b/src/Events/ConversionHasInputInformation.php @@ -22,7 +22,10 @@ public function __construct($message) { $this->message = $message; - if (config('media-convert.track_media_conversions')) { + if ( + config('media-convert.track_media_conversions') + && in_array('input_information', config('media-convert.events_to_track')) + ) { MediaConversion::createActivity($message); } } diff --git a/src/Events/ConversionHasNewWarning.php b/src/Events/ConversionHasNewWarning.php index e39c8c0..e491e5d 100644 --- a/src/Events/ConversionHasNewWarning.php +++ b/src/Events/ConversionHasNewWarning.php @@ -22,7 +22,10 @@ public function __construct($message) { $this->message = $message; - if (config('media-convert.track_media_conversions')) { + if ( + config('media-convert.track_media_conversions') + && in_array('new_warning', config('media-convert.events_to_track')) + ) { MediaConversion::createActivity($message); } } diff --git a/src/Events/ConversionHasStatusUpdate.php b/src/Events/ConversionHasStatusUpdate.php index 1906877..e5305eb 100644 --- a/src/Events/ConversionHasStatusUpdate.php +++ b/src/Events/ConversionHasStatusUpdate.php @@ -22,7 +22,10 @@ public function __construct($message) { $this->message = $message; - if (config('media-convert.track_media_conversions')) { + if ( + config('media-convert.track_media_conversions') + && in_array('status_update', config('media-convert.events_to_track')) + ) { MediaConversion::createActivity($message); } } diff --git a/src/Events/ConversionIsProgressing.php b/src/Events/ConversionIsProgressing.php index 567cb20..737a3ba 100644 --- a/src/Events/ConversionIsProgressing.php +++ b/src/Events/ConversionIsProgressing.php @@ -22,7 +22,10 @@ public function __construct($message) { $this->message = $message; - if (config('media-convert.track_media_conversions')) { + if ( + config('media-convert.track_media_conversions') + && in_array('progressing', config('media-convert.events_to_track')) + ) { MediaConversion::createActivity($message); } } diff --git a/src/Events/ConversionQueueHop.php b/src/Events/ConversionQueueHop.php index a89c26a..6d9dd1b 100644 --- a/src/Events/ConversionQueueHop.php +++ b/src/Events/ConversionQueueHop.php @@ -22,7 +22,10 @@ public function __construct($message) { $this->message = $message; - if (config('media-convert.track_media_conversions')) { + if ( + config('media-convert.track_media_conversions') + && in_array('queue_hop', config('media-convert.events_to_track')) + ) { MediaConversion::createActivity($message); } } diff --git a/src/Models/MediaConversion.php b/src/Models/MediaConversion.php index 9f0c8c6..4589a57 100644 --- a/src/Models/MediaConversion.php +++ b/src/Models/MediaConversion.php @@ -47,10 +47,10 @@ public static function createActivity($message) { $status = Str::lower($message['detail']['status']); - $percentage = $message['detail']['jobProgress']['jobPercentComplete'] ?? null; - if ($status === 'complete') { $percentage = 100; + } else { + $percentage = $message['detail']['jobProgress']['jobPercentComplete'] ?? null; } $conversion = new MediaConversion(); diff --git a/tests/DummyMessages.php b/tests/DummyMessages.php index 81c8967..ba4d781 100644 --- a/tests/DummyMessages.php +++ b/tests/DummyMessages.php @@ -12,8 +12,8 @@ class DummyMessages 'Content-Length' => '1520', 'x-amz-sns-message-type' => 'Notification', 'x-amz-sns-message-id' => '37210acf-236b-59e5-bbb8-52f4f85cd7b3', - 'x-amz-sns-topic-arn' => 'arn:aws:sns:us-east-2:923076644019:MediaConvertJobUpdate', - 'x-amz-sns-subscription-arn' => 'arn:aws:sns:us-east-2:923076644019:MediaConvertJobUpdate:186ceb0f-9602-4358-8773-168ff19a84e2', + 'x-amz-sns-topic-arn' => 'arn:aws:sns:us-east-2:954236614099:MediaConvertJobUpdate', + 'x-amz-sns-subscription-arn' => 'arn:aws:sns:us-east-2:954236614099:MediaConvertJobUpdate:186ceb0f-9602-4358-8773-168ff19a84e2', 'Content-Type' => 'text/plain; charset=UTF-8', 'User-Agent' => 'Amazon Simple Notification Service Agent', 'Accept-Encoding' => 'gzip, deflate', @@ -28,16 +28,16 @@ class DummyMessages 'id' => 'c5aebd1c-2c6a-ace0-3ab3-9945f986b4c4', 'detail-type' => 'MediaConvert Job State Change', 'source' => 'aws.mediaconvert', - 'account' => '923076644019', + 'account' => '954236614099', 'time' => '2020-11-28T04:58:31Z', 'region' => 'us-east-2', 'resources' => [ - 'arn:aws:mediaconvert:us-east-2:923076644019:jobs/1606539508649-2fu0hb', + 'arn:aws:mediaconvert:us-east-2:954236614099:jobs/1606539508649-2fu0hb', ], 'detail' => [ 'timestamp' => 1606539511533, - 'accountId' => '923076644019', - 'queue' => 'arn:aws:mediaconvert:us-east-2:923076644019:queues/Default', + 'accountId' => '954236614099', + 'queue' => 'arn:aws:mediaconvert:us-east-2:954236614099:queues/Default', 'jobId' => '1606539508649-2fu0hb', 'status' => 'PROGRESSING', 'userMetadata' => [ @@ -52,16 +52,16 @@ class DummyMessages 'id' => '810b18d6-8abd-03dd-5e1d-b0c52f387a05', 'detail-type' => 'MediaConvert Job State Change', 'source' => 'aws.mediaconvert', - 'account' => '923076644019', + 'account' => '954236614099', 'time' => '2020-11-28T04:58:34Z', 'region' => 'us-east-2', 'resources' => [ - 'arn:aws:mediaconvert:us-east-2:923076644019:jobs/1606539508649-2fu0hb', + 'arn:aws:mediaconvert:us-east-2:954236614099:jobs/1606539508649-2fu0hb', ], 'detail' => [ 'timestamp' => 1606539514554, - 'accountId' => '923076644019', - 'queue' => 'arn:aws:mediaconvert:us-east-2:923076644019:queues/Default', + 'accountId' => '954236614099', + 'queue' => 'arn:aws:mediaconvert:us-east-2:954236614099:queues/Default', 'jobId' => '1606539508649-2fu0hb', 'status' => 'STATUS_UPDATE', 'userMetadata' => [ @@ -96,16 +96,16 @@ class DummyMessages 'id' => '7f0eae16-c6d9-5511-0f77-93d2cbead642', 'detail-type' => 'MediaConvert Job State Change', 'source' => 'aws.mediaconvert', - 'account' => '923076644019', + 'account' => '954236614099', 'time' => '2020-11-28T04:59:51Z', 'region' => 'us-east-2', 'resources' => [ - 'arn:aws:mediaconvert:us-east-2:923076644019:jobs/1606539508649-2fu0hb', + 'arn:aws:mediaconvert:us-east-2:954236614099:jobs/1606539508649-2fu0hb', ], 'detail' => [ 'timestamp' => 1606539591681, - 'accountId' => '923076644019', - 'queue' => 'arn:aws:mediaconvert:us-east-2:923076644019:queues/Default', + 'accountId' => '954236614099', + 'queue' => 'arn:aws:mediaconvert:us-east-2:954236614099:queues/Default', 'jobId' => '1606539508649-2fu0hb', 'status' => 'STATUS_UPDATE', 'userMetadata' => [ @@ -139,16 +139,16 @@ class DummyMessages 'id' => '3b9aa7e1-45ab-cf2a-1787-913f4452d16b', 'detail-type' => 'MediaConvert Job State Change', 'source' => 'aws.mediaconvert', - 'account' => '923076644019', + 'account' => '954236614099', 'time' => '2020-11-28T05:00:03Z', 'region' => 'us-east-2', 'resources' => [ - 'arn:aws:mediaconvert:us-east-2:923076644019:jobs/1606539508649-2fu0hb', + 'arn:aws:mediaconvert:us-east-2:954236614099:jobs/1606539508649-2fu0hb', ], 'detail' => [ 'timestamp' => 1606539603045, - 'accountId' => '923076644019', - 'queue' => 'arn:aws:mediaconvert:us-east-2:923076644019:queues/Default', + 'accountId' => '954236614099', + 'queue' => 'arn:aws:mediaconvert:us-east-2:954236614099:queues/Default', 'jobId' => '1606539508649-2fu0hb', 'status' => 'COMPLETE', 'userMetadata' => [ @@ -172,7 +172,7 @@ class DummyMessages 'outputDetails' => [ [ 'outputFilePaths' => [ - 's3://meema-stage/chris/1/isI2oN3/hls/Raindrops_Videvo_1.m3u8', + 's3://meema-stage/some/path/isI2oN3/hls/Raindrops_Videvo_1.m3u8', ], 'durationInMs' => 58975, 'videoDetails' => [ @@ -182,7 +182,7 @@ class DummyMessages ], [ 'outputFilePaths' => [ - 's3://meema-stage/chris/1/isI2oN3/hls/Raindrops_Videvo_2.m3u8', + 's3://meema-stage/some/path/isI2oN3/hls/Raindrops_Videvo_2.m3u8', ], 'durationInMs' => 58975, 'videoDetails' => [ @@ -192,7 +192,7 @@ class DummyMessages ], [ 'outputFilePaths' => [ - 's3://meema-stage/chris/1/isI2oN3/hls/Raindrops_Videvo_3.m3u8', + 's3://meema-stage/some/path/isI2oN3/hls/Raindrops_Videvo_3.m3u8', ], 'durationInMs' => 58975, 'videoDetails' => [ @@ -202,7 +202,7 @@ class DummyMessages ], [ 'outputFilePaths' => [ - 's3://meema-stage/chris/1/isI2oN3/hls/Raindrops_Videvo_4.m3u8', + 's3://meema-stage/some/path/isI2oN3/hls/Raindrops_Videvo_4.m3u8', ], 'durationInMs' => 58975, 'videoDetails' => [ @@ -212,7 +212,7 @@ class DummyMessages ], [ 'outputFilePaths' => [ - 's3://meema-stage/chris/1/isI2oN3/hls/Raindrops_Videvo_5.m3u8', + 's3://meema-stage/some/path/isI2oN3/hls/Raindrops_Videvo_5.m3u8', ], 'durationInMs' => 58975, 'videoDetails' => [ @@ -222,7 +222,7 @@ class DummyMessages ], [ 'outputFilePaths' => [ - 's3://meema-stage/chris/1/isI2oN3/hls/Raindrops_Videvo_6.m3u8', + 's3://meema-stage/some/path/isI2oN3/hls/Raindrops_Videvo_6.m3u8', ], 'durationInMs' => 58975, 'videoDetails' => [ @@ -232,7 +232,7 @@ class DummyMessages ], ], 'playlistFilePaths' => [ - 's3://meema-stage/chris/1/isI2oN3/hls/Raindrops_Videvo.m3u8', + 's3://meema-stage/some/path/isI2oN3/hls/Raindrops_Videvo.m3u8', ], 'type' => 'HLS_GROUP', ], @@ -240,7 +240,7 @@ class DummyMessages 'outputDetails' => [ [ 'outputFilePaths' => [ - 's3://meema-stage/chris/1/isI2oN3/mp4/Raindrops_Videvo.mp4', + 's3://meema-stage/some/path/isI2oN3/mp4/Raindrops_Videvo.mp4', ], 'durationInMs' => 58975, 'videoDetails' => [ @@ -260,16 +260,16 @@ class DummyMessages 'id' => 'e9ebf388-8936-bd57-64e3-c2c1f1d78897', 'detail-type' => 'MediaConvert Job State Change', 'source' => 'aws.mediaconvert', - 'account' => '923076644019', + 'account' => '954236614099', 'time' => '2020-11-28T05:00:02Z', 'region' => 'us-east-2', 'resources' => [ - 'arn:aws:mediaconvert:us-east-2:923076644019:jobs/1606539508649-2fu0hb', + 'arn:aws:mediaconvert:us-east-2:954236614099:jobs/1606539508649-2fu0hb', ], 'detail' => [ 'timestamp' => 1606539602895, - 'accountId' => '923076644019', - 'queue' => 'arn:aws:mediaconvert:us-east-2:923076644019:queues/Default', + 'accountId' => '954236614099', + 'queue' => 'arn:aws:mediaconvert:us-east-2:954236614099:queues/Default', 'jobId' => '1606539508649-2fu0hb', 'status' => 'INPUT_INFORMATION', 'userMetadata' => [ @@ -279,7 +279,7 @@ class DummyMessages 'inputDetails' => [ [ 'id' => 1, - 'uri' => 's3://meema-stage/chris/1/isI2oN3/Raindrops_Videvo.mp4', + 'uri' => 's3://meema-stage/some/path/isI2oN3/Raindrops_Videvo.mp4', 'video' => [ [ 'bitDepth' => 8, @@ -305,20 +305,20 @@ class DummyMessages 'id' => '916792ce-208f-d04a-db2f-a573cf9b08bd', 'detail-type' => 'MediaConvert Job State Change', 'source' => 'aws.mediaconvert', - 'account' => '923076644019', + 'account' => '954236614099', 'time' => '2020-11-28T05:56:51Z', 'region' => 'us-east-2', 'resources' => [ - 'arn:aws:mediaconvert:us-east-2:923076644019:jobs/1606542703411-00h7yw', + 'arn:aws:mediaconvert:us-east-2:954236614099:jobs/1606542703411-00h7yw', ], 'detail' => [ 'timestamp' => 1606543011394, - 'accountId' => '923076644019', - 'queue' => 'arn:aws:mediaconvert:us-east-2:923076644019:queues/Default', + 'accountId' => '954236614099', + 'queue' => 'arn:aws:mediaconvert:us-east-2:954236614099:queues/Default', 'jobId' => '1606542703411-00h7yw', 'status' => 'ERROR', 'errorCode' => 1404, - 'errorMessage' => 'Unable to open input file [s3://meema-stage/chris/1/AoTef8Z/Raindrops_Videvo.mp4]: [Failed probe/open: [Failed to read data: HeadObject failed]]', + 'errorMessage' => 'Unable to open input file [s3://meema-stage/some/path/AoTef8Z/Raindrops_Videvo.mp4]: [Failed probe/open: [Failed to read data: HeadObject failed]]', 'userMetadata' => [ 'model_id' => '23', 'hello' => 'world',