Skip to content

Commit

Permalink
feat: Add jobs.delete and update to latest discovery types (#1023)
Browse files Browse the repository at this point in the history
* feat: add jobs.delete

* fix test

* refactor

* lint

* lint

* update jobs test

* refactor

* lint

* remove unnecessary DeleteCallback

* remove unnecessary DeleteCallback

* update

* add deleteJobs() to system-test to delete stale job resources

* remove unnecessary jobs cleanup
  • Loading branch information
steffnay committed Jan 10, 2022
1 parent 65baa65 commit 12f7771
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/job.ts
Expand Up @@ -134,6 +134,53 @@ class Job extends Operation {
let location: string;

const methods = {
/**
* @callback DeleteJobCallback
* @param {?Error} err Request error, if any.
* @param {object} apiResponse The full API response.
*/
/**
* @typedef {array} DeleteJobResponse
* @property {object} 0 The full API response.
*/
/**
* Delete the job.
*
* @see [Jobs: delete API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/delete}
*
* @method Job#delete
* @param {DeleteJobCallback} [callback] The callback function.
* @param {?error} callback.err An error returned while making this
* request.
* @param {object} callback.apiResponse The full API response.
* @returns {Promise<DeleteJobResponse>}
*
* @example
* const {BigQuery} = require('@google-cloud/bigquery');
* const bigquery = new BigQuery();
*
* const job = bigquery.job(jobId);
* job.delete((err, apiResponse) => {
* if (!err) {
* // The job was deleted successfully.
* }
* });
*
* @example If the callback is omitted a Promise will be returned
* const [apiResponse] = await job.delete();
*/
delete: {
reqOpts: {
method: 'DELETE',
uri: '/delete',
qs: {
get location() {
return location;
},
},
},
},

/**
* @callback JobExistsCallback
* @param {?Error} err Request error, if any.
Expand Down
19 changes: 19 additions & 0 deletions system-test/bigquery.ts
Expand Up @@ -646,6 +646,25 @@ describe('BigQuery', () => {
});
});

describe('BigQuery/Job', () => {
it('should delete a job', async () => {
const opts = {
configuration: {
query: {
query: 'SELECT 100 as foo',
},
},
location: 'us-east1',
};

const [job] = await bigquery.createJob(opts);
const [resp] = await job.delete();
const [exists] = await job.exists();
assert.deepStrictEqual(resp, {});
assert.strictEqual(exists, false);
});
});

describe('BigQuery/Model', () => {
let model: Model;
const bucket = storage.bucket(generateName('bucket'));
Expand Down
7 changes: 7 additions & 0 deletions test/job.ts
Expand Up @@ -123,6 +123,13 @@ describe('BigQuery/Job', () => {
assert.strictEqual(calledWith.baseUrl, '/jobs');
assert.strictEqual(calledWith.id, JOB_ID);
assert.deepStrictEqual(calledWith.methods, {
delete: {
reqOpts: {
method: 'DELETE',
uri: '/delete',
qs: {location: undefined},
},
},
exists: true,
get: true,
getMetadata: {
Expand Down

0 comments on commit 12f7771

Please sign in to comment.