Skip to content

Commit 4353569

Browse files
authored
ci(scheduler): migrate to new CI (#4006)
* ci(scheduler): migrate to new CI * 'npm run build' output * restore generated note * mark as module * exports * update config, regenerate * debug: extend timeout
1 parent 0ef037a commit 4353569

File tree

5 files changed

+30
-38
lines changed

5 files changed

+30
-38
lines changed

.github/config/nodejs-dev.jsonc

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
"secret-manager",
207207
"security-center/snippets",
208208
"service-directory/snippets",
209+
"scheduler",
209210
"storage-control",
210211
"speech",
211212
"talent",

.github/config/nodejs-prod.jsonc

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
"iam/deny", // PERMISSION_DENIED: Permission iam.googleapis.com/denypolicies.create denied on resource cloudresourcemanager.googleapis.com/projects/long-door-651
9898
"recaptcha_enterprise/snippets", // Cannot use import statement outside a module
9999
"run/idp-sql", // (untested) Error: Invalid contents in the credentials file
100-
"scheduler", // SyntaxError: Cannot use import statement outside a module
101100
"storagetransfer", // CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
102101
"video-intelligence", // PERMISSION_DENIED: The caller does not have permission
103102
"vision", // REDIS: Error: connect ECONNREFUSED 127.0.0.1:6379

scheduler/createJob.js

+25-35
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,50 @@
1414

1515
// This is a generated sample, using the typeless sample bot. Please
1616
// look for the source TypeScript sample (.ts) for modifications.
17-
'use strict';
1817

1918
// sample-metadata:
2019
// title: Create Job
2120
// description: Create a job that posts to /log_payload on an App Engine service.
2221
// usage: node createJob.js [project-id] [location-id] [app-engine-service-id]
23-
2422
const args = process.argv.slice(2);
2523
const [projectId, locationId, serviceId] = args;
26-
2724
// [START cloudscheduler_create_job]
28-
const {CloudSchedulerClient} = require('@google-cloud/scheduler');
29-
25+
import { CloudSchedulerClient } from '@google-cloud/scheduler';
3026
// TODO(developer): Uncomment and set the following variables
3127
// const projectId = "PROJECT_ID"
3228
// const locationId = "LOCATION_ID"
3329
// const serviceId = "my-serivce"
34-
3530
// Create a client.
3631
const client = new CloudSchedulerClient();
37-
3832
/**
3933
* Create a job with an App Engine target via the Cloud Scheduler API
4034
*/
4135
async function createJob(projectId, locationId, serviceId) {
42-
// Construct the fully qualified location path.
43-
const parent = client.locationPath(projectId, locationId);
44-
45-
// Construct the request body.
46-
const job = {
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 = {
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}`);
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}`);
6758
}
68-
6959
createJob(projectId, locationId, serviceId).catch(err => {
70-
console.error(err.message);
71-
process.exitCode = 1;
60+
console.error(err.message);
61+
process.exitCode = 1;
7262
});
7363
// [END cloudscheduler_create_job]

scheduler/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "nodejs-scheduler-samples",
33
"private": true,
44
"main": "quickstart.js",
5+
"type": "module",
56
"engines": {
67
"node": ">=16.0.0"
78
},
@@ -14,7 +15,7 @@
1415
"build": "tsc -p .",
1516
"fix": "gts fix",
1617
"lint": "gts lint",
17-
"test": "c8 mocha -p -j 2 --loader=ts-node/esm --extension ts --timeout 10000 --exit"
18+
"test": "c8 mocha -p -j 2 --loader=ts-node/esm --extension ts --timeout 20000 --exit"
1819
},
1920
"dependencies": {
2021
"@google-cloud/scheduler": "^4.0.0"

scheduler/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"strict": true,
55
"noImplicitAny": false,
66
"esModuleInterop": true,
7-
"moduleResolution": "node"
7+
"moduleResolution": "node",
8+
"module": "ESNext"
89
}
910
}

0 commit comments

Comments
 (0)