Skip to content

Commit

Permalink
docs: update to useful quickstart
Browse files Browse the repository at this point in the history
docs: update to useful quickstart

* adds a quickstart that does more than simply pull in the library.
* demonstrates the new `sample-metadata:` stanza we can provide in samples.

- [x] Tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)

CC: @steffnay

#78 automerged by dpebot
  • Loading branch information
bcoe authored and yoshi-automation committed Apr 24, 2019
1 parent cabfa83 commit 1a103e1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
10 changes: 9 additions & 1 deletion scheduler/createJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
* limitations under the License.
*/

// sample-metadata:
// title: Create Job
// description: Create a job that posts to /log_payload on an App Engine service.
// usage: node createJob.js [project-id] [location-id] [app-engine-service-id]

/**
* Create a job with an App Engine target via the Cloud Scheduler API
*/
Expand Down Expand Up @@ -57,4 +62,7 @@ async function createJob(projectId, locationId, serviceId) {
}

const args = process.argv.slice(2);
createJob(...args).catch(console.error);
createJob(...args).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
10 changes: 9 additions & 1 deletion scheduler/deleteJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
* limitations under the License.
*/

// sample-metadata:
// title: Delete Job
// description: Delete a job by its ID.
// usage: node deleteJob.js [project-id] [location-id] [job-id]

/**
* Delete a job via the Cloud Scheduler API
*/
Expand All @@ -38,4 +43,7 @@ async function deleteJob(projectId, locationId, jobId) {
}

const args = process.argv.slice(2);
deleteJob(...args).catch(console.error);
deleteJob(...args).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
51 changes: 46 additions & 5 deletions scheduler/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,49 @@

'use strict';

// [START scheduler_quickstart]
// Imports the Google Cloud client library
const scheduler = require('@google-cloud/scheduler');
console.log(scheduler);
// [END scheduler_quickstart]
// sample-metadata:
// title: Quickstart
// description: POST "Hello World" to a URL every minute.
// usage: node quickstart.js [project-id] [location-id] [url]

async function main(projectId, locationId, url) {
// [START scheduler_quickstart]
// const projectId = "PROJECT_ID"
// const locationId = "LOCATION_ID" // see: https://cloud.google.com/about/locations/
// const url = "https://postb.in/..." // where should we say hello?

const scheduler = require('@google-cloud/scheduler');

// Create a client.
const client = new scheduler.CloudSchedulerClient();

// Construct the fully qualified location path.
const parent = client.locationPath(projectId, locationId);

// Construct the request body.
const job = {
httpTarget: {
uri: url,
httpMethod: 'POST',
body: Buffer.from('Hello World'),
},
schedule: '* * * * *',
timeZone: 'America/Los_Angeles',
};

const request = {
parent: parent,
job: job,
};

// Use the client to send the job creation request.
const [response] = await client.createJob(request);
console.log(`Created job: ${response.name}`);
// [END scheduler_quickstart]
}

const args = process.argv.slice(2);
main(...args).catch(err => {
console.error(err.message);
process.exitCode = 1;
});

0 comments on commit 1a103e1

Please sign in to comment.