diff --git a/src/job.ts b/src/job.ts index c26afbff..72c8ec45 100644 --- a/src/job.ts +++ b/src/job.ts @@ -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} + * + * @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. diff --git a/system-test/bigquery.ts b/system-test/bigquery.ts index 2810e899..f5603276 100644 --- a/system-test/bigquery.ts +++ b/system-test/bigquery.ts @@ -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')); diff --git a/test/job.ts b/test/job.ts index ab195ff8..ce39a7cc 100644 --- a/test/job.ts +++ b/test/job.ts @@ -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: {