/**
* Fetches jobs in the project.
*
* Example:
* ```
* // Get all jobs with the state of 'done'
* $jobs = $bigQuery->jobs([
* 'stateFilter' => 'done'
* ]);
*
* foreach ($jobs as $job) {
* var_dump($job->id());
* }
* ```
*
* @see https://cloud.google.com/bigquery/docs/reference/v2/jobs/list Jobs list API documentation.
*
* @param array $options [optional] {
* Configuration options.
*
* @type bool $allUsers Whether to display jobs owned by all users in
* the project. **Defaults to** `false`.
* @type int $maxResults Maximum number of results to return.
* @type string $stateFilter Filter for job state. Maybe be either
* `done`, `pending`, or `running`.
* }
* @return \Generator<Google\Cloud\BigQuery\Job>
*/
public function jobs(array $options = [])
{
$options['pageToken'] = null;
do {
$response = $this->connection->listJobs($options + ['projectId' => $this->projectId]);
if (!isset($response['jobs'])) {
return;
}
foreach ($response['jobs'] as $job) {
(yield new Job($this->connection, $job['jobReference']['jobId'], $this->projectId, $job));
}
$options['pageToken'] = isset($response['nextPageToken']) ? $response['nextPageToken'] : null;
} while ($options['pageToken']);
}