Skip to content

improved transcoding workflow for local development#2594

Draft
umar8hassan wants to merge 1 commit intomasterfrom
umar/7639-improved-video-transcoding-workflow-for-local-development
Draft

improved transcoding workflow for local development#2594
umar8hassan wants to merge 1 commit intomasterfrom
umar/7639-improved-video-transcoding-workflow-for-local-development

Conversation

@umar8hassan
Copy link
Copy Markdown
Contributor

What are the relevant tickets?

Description (What does it do?)

This PR address the Phase - 1: of the linked issue which involves the following steps:

  1. environment = dev:
    If the task does NOT involve testing Transcoding with MediaConvert, simply copy/paste the original video in the locations to mock the Transcoding task

  2. environment = staging:
    If the task involves testing Transcoding with MediaConvert, submit the task to AWS and mock the callback on completion. This would involve the following steps:

    • Celery Beat: to check task status periodically for all submitted Jobs
    • Mock Callback: Compile results from a template and complete/fail job

How can this be tested?

TBA

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @umar8hassan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the video transcoding workflow, particularly for local development and testing. It introduces a robust system for mocking AWS MediaConvert responses, enabling developers to simulate transcoding job completions and failures without relying on actual AWS services. This automation streamlines the testing process, improves error handling, and provides more accurate status tracking for video jobs.

Highlights

  • Enhanced Local Transcoding Workflow: Introduced a new Celery task (update_video_transcoding_statuses) that periodically checks and updates the status of transcoding videos. This task simulates AWS MediaConvert callbacks for local development and testing, using configurable JSON templates for both success and error scenarios.
  • Dynamic Mocking with Placeholders: Implemented a prepare_job_results utility that dynamically populates mock AWS MediaConvert responses. It replaces placeholders (e.g., <VIDEO_JOB_ID>, <DRIVE_FILE_ID>, <AWS_ACCOUNT_ID>) in JSON templates with real-time video, job, and environment-specific data, making local testing more realistic and flexible.
  • Improved Transcoding Status Management: The system now includes a get_media_convert_job function to retrieve AWS MediaConvert job details and a more resilient update_video_job function that handles case-insensitive statuses and gracefully processes output details. The VideoJobStatus enum was extended with an ERROR status.
  • Comprehensive Documentation Updates: The README.md and videos/README.md files have been significantly updated to provide clear instructions and explanations for configuring and utilizing the new local development and testing features, including required environment variables and detailed testing workflows.
  • New Configuration Options: Several new environment variables have been introduced (VIDEO_TRANSCODING_STATUS_UPDATE_FREQUENCY, TRANSCODE_RESULT_TEMPLATE, TRANSCODE_ERROR_TEMPLATE, VIDEO_S3_TRANSCODE_BUCKET, POST_TRANSCODE_ACTIONS) to control the frequency of status updates, specify mock result/error templates, and configure post-transcoding actions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The code changes introduce an improved transcoding workflow for local development, including periodic status updates and mock AWS MediaConvert callbacks. The changes also include updates to documentation and test files to reflect the new workflow.

Comment thread .secrets.baseline
Comment thread videos/api.py
@@ -67,8 +69,11 @@ def create_media_convert_job(video: Video):
video.save()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a check to ensure output_group_details is not None or empty before iterating to avoid potential errors.

Suggested change
if not output_group_details:
return

Comment thread videos/api.py
process_video_outputs(video, results.get("outputGroupDetails"))
output_group_details = results.get("outputGroupDetails", [])
process_video_outputs(video, output_group_details)
except: # pylint:disable=bare-except # noqa: E722
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Catching a bare exception is generally discouraged. Consider catching specific exceptions like KeyError, TypeError, or ValueError to handle potential issues more gracefully and avoid masking unexpected errors.1

Style Guide References

Suggested change
except: # pylint:disable=bare-except # noqa: E722
except (KeyError, TypeError, ValueError): # pylint:disable=bare-except # noqa: E722

Footnotes

  1. Catching a bare exception is generally discouraged. Consider catching specific exceptions to handle potential issues more gracefully and avoid masking unexpected errors. (link)

Comment thread videos/api.py

# Decode the JSON string
try:
return json.loads(results)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Catching a bare exception is generally discouraged. Consider catching specific exceptions like json.JSONDecodeError to handle potential issues more gracefully and avoid masking unexpected errors.1

Style Guide References

Suggested change
return json.loads(results)
except json.JSONDecodeError:

Footnotes

  1. Catching a bare exception is generally discouraged. Consider catching specific exceptions to handle potential issues more gracefully and avoid masking unexpected errors. (link)

Comment thread videos/tasks.py
Comment on lines +594 to +596
media_convert_job["Job"]["Status"].lower()
== VideoJobStatus.COMPLETE.lower()
):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a check to ensure media_convert_job is not None and contains the 'Job' key before accessing it to prevent potential KeyError exceptions.

            if media_convert_job and "Job" in media_convert_job and media_convert_job["Job"]["Status"].lower() == VideoJobStatus.COMPLETE.lower():

Comment thread videos/tasks.py
Comment on lines +602 to +604
elif (
media_convert_job["Job"]["Status"].lower()
== VideoJobStatus.ERROR.lower()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a check to ensure media_convert_job is not None and contains the 'Job' key before accessing it to prevent potential KeyError exceptions.

            elif media_convert_job and "Job" in media_convert_job and media_convert_job["Job"]["Status"].lower() == VideoJobStatus.ERROR.lower():

Comment thread videos/tasks.py
Comment on lines +616 to +618
if results is not None:
for action in settings.POST_TRANSCODE_ACTIONS:
import_string(action)(results.get("detail", {}))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a check to ensure settings.POST_TRANSCODE_ACTIONS is not None or empty before iterating to avoid potential errors.

            if results is not None and settings.POST_TRANSCODE_ACTIONS:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant