Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add jobs.delete #1023

Merged
merged 25 commits into from Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
46e1363
feat: add jobs.delete
steffnay Oct 4, 2021
7dddde7
Merge branch 'googleapis:main' into add-jobs-delete
steffnay Oct 8, 2021
e0d7820
fix test
steffnay Oct 8, 2021
1f3a2a4
Merge branch 'main' into add-jobs-delete
steffnay Oct 25, 2021
5179b9c
Merge branch 'main' into add-jobs-delete
steffnay Oct 26, 2021
3e03676
Merge branch 'main' into add-jobs-delete
steffnay Nov 3, 2021
da5072d
merge main
steffnay Nov 11, 2021
76bfa9e
refactor
steffnay Nov 13, 2021
70622a8
lint
steffnay Nov 13, 2021
6f5e237
lint
steffnay Nov 14, 2021
af6a343
update jobs test
steffnay Nov 14, 2021
5d3c2a4
refactor
steffnay Nov 15, 2021
4d9627f
lint
steffnay Nov 15, 2021
0ac4676
remove unnecessary DeleteCallback
steffnay Nov 15, 2021
85eab00
remove unnecessary DeleteCallback
steffnay Nov 15, 2021
b123d58
Merge branch 'main' into add-jobs-delete
steffnay Nov 16, 2021
36339fa
Merge branch 'main' into add-jobs-delete
steffnay Nov 22, 2021
a33281f
Merge branch 'main' into add-jobs-delete
steffnay Dec 4, 2021
7f95964
update
steffnay Dec 7, 2021
2924b77
Merge branch 'main' into add-jobs-delete
steffnay Dec 7, 2021
ae51692
Merge branch 'main' into add-jobs-delete
steffnay Dec 15, 2021
151e02d
Merge branch 'main' of https://github.com/googleapis/nodejs-bigquery …
steffnay Jan 2, 2022
314457d
add deleteJobs() to system-test to delete stale job resources
steffnay Jan 2, 2022
bda46c4
Merge branch 'add-jobs-delete' of github.com:steffnay/nodejs-bigquery…
steffnay Jan 2, 2022
54bd2fb
remove unnecessary jobs cleanup
steffnay Jan 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
steffnay marked this conversation as resolved.
Show resolved Hide resolved
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