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