Media Workflow Job Spawner Function
Find out how to use the Media Workflow Job Spawner pre-built function in OCI Functions to trigger a media workflow job when video content is uploaded to an Object Storage bucket.
Common Usage Scenarios
Common ways to use the Media Workflow Job Spawner function include:
- Encode a video file in different resolutions after uploading a video file into a bucket.
- Encode an audio file at different bit rates after uploading an audio file into a bucket.
Services related to the Media Workflow Job Spawner function include:
Scope
Scope considerations for this function include:
- The pre-built function only honors the event type "Object – Create". The pre-built function proceeds to trigger the media workflow job only if a new object is created in the source bucket.
- The pre-built function doesn't wait for the media workflow job to complete. The function simply triggers the job.
Prerequisites and Recommendations
The following are best practices when using this pre-built function:
- Set the pre-built function timeout to 300 seconds.
- The VCN linked to the application facilitates access to other OCI services by using a Service Gateway, Internet Gateway, or NAT gateway.
Configuring the Media Workflow Job Spawner Function
To configure a Media Workflow Job Spawner function, perform the following steps:
The deploy dialog displays the tasks to deploy the function (see Finishing Pre-Built Function Deployment).
Configuration Options
Configuration Parameters
Name | Description | Required |
---|---|---|
MEDIA_WORKFLOW_ID |
ID of the media workflow created for the job. Default is null . |
Yes |
DESTINATION_BUCKET |
Name of the object storage bucket where you want to save the output of the job. The default is the bucket specified here. | No |
DESTINATION_COMPARTMENT_ID |
ID of the compartment in which destination bucket is present. Default is compartment in which media workflow is created. | No |
PBF_LOG_LEVEL |
Logging level, options are DEBUG ,
INFO , WARN , and
ERROR . Defaults to
INFO . |
No |
Permissions
Running a function requires certain IAM policies. If you selected the Do not create a dynamic group and IAM policy option when creating the function, you must define the dynamic group and the IAM policy yourself.
To set the proper policies, perform the following steps:
- Create a dynamic group with the rule:
ALL {resource.id = '<function_ocid>', resource.compartment.id = '<compartment_ocid>'
- Configure an IAM policy using the dynamic group:
Allow dynamic-group <dynamic-group-name> to use media-workflow in compartment <dynamic-group-name> Allow dynamic-group <dynamic-group-name> to manage media-workflow-job in compartment <compartment-name> Allow dynamic-group <dynamic-group-name> to manage object-family in compartment <compartment-name> Allow dynamic-group <dynamic-group-name> to manage media-asset in compartment <compartment-name> Allow dynamic-group <dynamic-group-name> to manage functions-family in compartment <compartment-name>
Replace
<function-ocid>
with the OCID of the function that you created in preceding steps. Replace
<dynamic-group-name>
with the name of the dynamic group that you created using the function's OCID.Replace
<compartment_ocid>
with the OCID of the compartment that contains the function.Invoking This Function
Create two conditions in the event rule:
- Condition as "Event Type", Service name as "Object Storage", and Event Type as "Object – Create".
- Condition as "Attribute", Attribute Name as "bucketName", and provide the name of your source bucket in "Attribute Values".
The invocation of the pre-built function follows these steps:
- Putting a video file in object store triggers an event.
- A rule matches the event and invokes the pre-built function.
- The pre-built function submits a job that converts the video file and puts the file in the destination bucket.
Response Body
- Timestamps: Using UTC to avoid time zone issues.
- Code: The function returns a 200 code if the task completes successfully.
- Status: The function returns "Success" as the status if the task completes successfully.
- data: A JSON message body that includes specific response information for the task.
Example
The following example shows the JSON return data:
{
"startTime": "2023-02-22T05:03:13.029Z",
"endTime": "2023-02-22T05:03:24.436Z",
"runTime": "PT11.407S",
"code": 200,
"status": "Success",
"data": {
"additionalInformation": {
"MediaWorkFlowJobId": "ocid1.mediaworkflowjob.oc1.us-ashburn-1.amaaaa...."
}
}
}
Troubleshooting
OCI Functions common status codes
The following table summarizes common OCI Functions errors that you might encounter when working with pre-built functions:
Error Code | Error Message | Action |
---|---|---|
200 | Success | None |
404 | NotAuthorizedOrNotFound | Verify that the required policies are configured (see Running Fn Project CLI commands returns a 404 error). |
444 | Timeout |
The connection between the client and OCI Functions was interrupted during function execution (see Invoking a function causes the client to report a timeout, and a 444 error is shown in the function's logs). A retry might solve the issue. Note that most clients have an inner timeout of 60 seconds. Even when the pre-built function timeout is set to 300 seconds, the following might be required:
For more information, see Invoking Functions. |
502, 504 | (various) | Most issues return a 502 status code (see Invoking a function returns a Function failed message and a 502 error). A 502 error with the message "error receiving function response" might be resolved by increasing the memory allocation. A 502 might occur occasionally when the function is in some transient state. A retry might solve the issue. |
To further identify the cause, enable logging features for the pre-built function (see Storing and Viewing Function Logs). For detailed information on troubleshooting a function, see Troubleshooting OCI Functions.
Media Workflow Job Spawner Pre-Built Function status codes
The following table summarizes the errors that you might encounter when working with this pre-built function:
Error Code | Error Message | Action |
---|---|---|
400 | Function payload has wrong Event Type | Verify whether the event type is "Object - Create". |
To further identify the cause, enable logging features for the pre-built function (see Storing and Viewing Function Logs).
Log Analysis Tips
All the pre-built functions provide an option to specify the logging level as a configuration parameter. You can set the logging level to DEBUG
to get more information.
Since an application has multiple functions, the pre-built function log entries are identified by the prefix "PBF | <PBF NAME> ".
For example, a log entry for the Media Workflow Job Spawner pre-built function looks similar to the following:
"PBF | Media Workflow Job Spawner | INFO | 2023-02-07T18:06:50.809Z | Fetching details from Events JSON"