Luciano Salemme
Luciano Salemme

Reputation: 387

Unable to retrive ordered job list from Google Transcoder API

i'm using the node.js client library of google transcoder api. I'm able to retrive a paginated list of some jobs, but i'm not able to order elements by start date. Here my codes:

const { TranscoderServiceClient } = require('@google-cloud/video-transcoder').v1;

class TranscoderApiController {

    constructor() {
        this.projectId = process.env.GOOGLE_CLOUD_PROJECT;
        this.location = process.env.TASK_LOCATION;
    }

    async getEntries(req, res, next) {
        const params = {
            pageSize: req.query.pageSize ? parseInt(req.query.pageSize) : 10,
            pageToken: req.query.pageToken,
            filter: req.query.filter,
            orderBy: req.query.orderBy
        }
        const client = new TranscoderServiceClient();
        const result = await client.listJobs({
            parent: client.locationPath(this.projectId, this.location),
            pageSize: params.pageSize,
            orderBy: 'createTime.seconds'
        }, {
            autoPaginate: false
        });
        if (result.length == 3 && result[2] != undefined) {
            return result[2];
        } else {
            return result[1];
        }

    }


}

module.exports = new TranscoderApiController();

When i call the getEntries method i receive the following error:

"3 INVALID_ARGUMENT: The request was invalid: sort order \"createTime.seconds\" is unsupported"

If i remove the orderBy: 'createTime.seconds' line then the api works but is not ordered as i want. The result is something like that (i abbreviate the json):

{
    "jobs": [
        {
            "labels": {},
            "name": "projects/<id>/locations/europe-west1/jobs/<uuid>",
            "inputUri": "",
            "outputUri": "",
            "state": "SUCCEEDED",
            "createTime": {
                "seconds": "1656602896",
                "nanos": 386772728
            },
            "startTime": {
                "seconds": "1656602900",
                "nanos": 755000000
            },
            "endTime": {
                "seconds": "1656603062",
                "nanos": 428000000
            },
            "ttlAfterCompletionDays": 30,
            "error": null,
            "config": {
                "inputs": [
                    {
                        "key": "input0",
                        "uri": "gs://<url>/render_md.mp4",
                        "preprocessingConfig": null
                    }
                ],
                "editList": [...],
                "elementaryStreams": [...],
                "muxStreams": [...],
                "manifests": [],
                "adBreaks": [],
                "spriteSheets": [],
                "overlays": [],
                "output": {
                    "uri": "gs://<url>/md.mp4/"
                },
                "pubsubDestination": {
                    "topic": "projects/<id>/topics/transcoder_api"
                }
            },
            "jobConfig": "config"
        },
        ... 
    ],
    "unreachable": [],
    "nextPageToken": "Co8BCjgKDGV1cm9wZS13ZXN0MRIZdHJhbnNjb2Rlci5nb29nbGVhcGlzLmNvbRgBII..."
}

As you can see each job have the startTime.seconds property. I follow the syntax described here:

https://google.aip.dev/132#ordering

Any support to solve the ordered issue is appreciated.

Upvotes: 0

Views: 196

Answers (0)

Related Questions