1

I am currently working on a PHP project using the AWS PHP SDK. I have a data import process that utilizes AWS batch. The PHP application needs to be able to check AWS for jobs that are not complete, prior to letting the user start a new job.

I am currently using the listJobs() call on the BacthClint like so, following an example given by the documentation:

<?php

$client = new Aws\Batch\BatchClient([
    ...
]);

$jobs = $client->listJobs([
    'jobQueue' => '...',
    'jobStatus' => 'RUNNING',
]);

However, I would like to get jobs matching the statuses of SUBMITTED, PENDING, RUNNABLE and STARTING as well as RUNNING.

The docs make it seem like I could submit the following value, as a pipe delinted list. But this syntax caused the request to fail:

<?php

$jobs = $client->listJobs([
    'jobQueue' => '...',
    'jobStatus' => 'SUBMITTED|PENDING|RUNNABLE|STARTING|RUNNING',
]);

Error:

Error executing request, Exception : Invalid job status SUBMITTED|PENDING|RUNNABLE|STARTING|RUNNING. Valid statuses are [SUBMITTED, PENDING, RUNNABLE, STARTING, RUNNING, SUCCEEDED, FAILED]

Is there some kind of way that I can submit multiple values under the 'jobStatus' input?

If not, is there some other way I can do this utilizing the AWS PHP SDK?

Note:

It looks like there is a 'filters' feature listed under the heading "Parameter Details" and "Parameter Syntax" secotion in the documentation example from before. This seems to suggest that something like this should work:

<?php

$jobs = $client->listJobs([
    'jobQueue' => '...',
    'filters' => [
        'name' => 'jobStatus',
        'values' => ['SUBMITTED', 'PENDING', 'RUNNABLE', 'STARTING', 'RUNNING']
    ]
]);

"You can filter the results by job status with the jobStatus parameter. If you don't specify a status, only RUNNING jobs are returned."

"The job status used to filter jobs in the specified queue. If the filters parameter is specified, the jobStatus parameter is ignored and jobs with any status are returned. If you don't specify a status, only RUNNING jobs are returned."

However this seems to return blank result sets.

space97
  • 153
  • 1
  • 4
  • 19
  • Any error, you get when using `$result = $client->listJobs([ 'jobQueue' => '', 'jobStatus' => 'SUBMITTED|PENDING|RUNNABLE|STARTING|RUNNING|SUCCEEDED|FAILED', ]);` ? – Arpit Jain Dec 07 '22 at 11:02
  • @Arpit Jain No problem! I have added the error to the question. – space97 Dec 07 '22 at 15:42
  • 1
    Hi @space97, can you please give one last shot with below line:- `$result = $client->listJobs([ 'jobQueue' => '', 'jobStatus' => ['SUBMITTED', 'PENDING', 'RUNNABLE', 'STARTING', 'RUNNING'], ]); ` – Arpit Jain Dec 08 '22 at 10:37
  • @ArpitJain According to the documentation and above the input for jobStatus has to be a string (not an array) that is equal to one of the valid job statuses. You can see that here: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-batch-2016-08-10.html#listjobs Here is the error you requested, when you use that input: "Found 1 error while validating the input provided for the ListJobs operation:[jobStatus] must be a string or an object that implements __toString(). Found array(7)" – space97 Dec 08 '22 at 17:41
  • Hmm, I also tried at my end for all the possible ways to get all the jobs to match multiple statuses but it mostly gave syntax errors that seem like we can only get jobs with single status only :( – Arpit Jain Dec 09 '22 at 09:42
  • Thanks, yeah this one has been tricky. – space97 Dec 09 '22 at 13:24

0 Answers0