MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / createJob

Function createJob

scheduler/createJob.ts:37–67  ·  view source on GitHub ↗

* Create a job with an App Engine target via the Cloud Scheduler API

(
  projectId: string,
  locationId: string,
  serviceId: string
)

Source from the content-addressed store, hash-verified

35 * Create a job with an App Engine target via the Cloud Scheduler API
36 */
37async function createJob(
38 projectId: string,
39 locationId: string,
40 serviceId: string
41) {
42 // Construct the fully qualified location path.
43 const parent: string = client.locationPath(projectId, locationId);
44
45 // Construct the request body.
46 const job: protos.google.cloud.scheduler.v1.IJob = {
47 appEngineHttpTarget: {
48 appEngineRouting: {
49 service: serviceId,
50 },
51 relativeUri: '/log_payload',
52 httpMethod: 'POST',
53 body: Buffer.from('Hello World'),
54 },
55 schedule: '* * * * *',
56 timeZone: 'America/Los_Angeles',
57 };
58
59 const request: protos.google.cloud.scheduler.v1.ICreateJobRequest = {
60 parent: parent,
61 job: job,
62 };
63
64 // Use the client to send the job creation request.
65 const [response] = await client.createJob(request);
66 console.log(`Created job: ${response.name}`);
67}
68
69createJob(projectId, locationId, serviceId).catch(err => {
70 console.error(err.message);

Callers 1

createJob.tsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected