0

I'm using the AWS SDK for Javascript and, I have this code for reading a job:


const getJobOutputDuration=async()=>{
   // read jobInfo
   const jobDetailsResult = const result = await elasticTranscoder.readJob({ Id: jobId }).promise();
  // if not found, throw an error
  if (! jobDetailsResult.Job?.Id) {
      throw new Error("Job object not found!");
    }

  // read output duration from job
  const outputDuration = jobDetails.Job.Output?.Duration
  return outputDuration;
}

But sometimes, the outputDuration returns undefined. The code flow is:

  1. Trigger a job on ElasticTranscoder
  2. Save the Elastic Transcoder jobId on the database
  3. Once ElasticTranscoder finishes, it saves the output file in an S3 bucket
  4. The S3 bucket emits an event to SNS
  5. SNS sends the event to an endpoint in my code
  6. The code runs the function getJobOutputDuration previously defined

Ps: I noticed that when I try to run the same code after a few minutes, it does return the output duration correctly

  • I asked the same problem to ChatGPT and, it said that, due to the fact that some AWS services are eventually consistent, it might take some time to update all of its nodes. So, ChatGPT suggested to make a function that retries getting the output duration if the same is undefined. – Marcos Paulo Júnior Apr 28 '23 at 15:44

0 Answers0