Skip to content

Commit 527d98d

Browse files
authored
Merge pull request #1965 from Automattic/fix/1964-cloudflare-publication-cpu
Bound Cloudflare publication scheduler CPU
2 parents 0568375 + 5a10330 commit 527d98d

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

packages/runtime-cloudflare/src/worker.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ async function drainNextPublicationJob(env: RuntimeEnv, coordinator: RevisionCoo
586586
if (progress.next < plan.upsert.length) {
587587
const route = plan.upsert[progress.next]
588588
runtime = await bootRuntime(env.WORDPRESS_STATE_BUCKET, job.canonical, SITE_URL, await canonicalWordPressAuthConstants(env))
589-
const compiled = await compilePublicationRoutes(runtime, [route], await runtimeSiteOrigin(runtime))
589+
const compiled = await compilePublicationRoutes(runtime, [route], SITE_URL)
590590
const page = compiled[0]
591591
const objectKey = await publishedPageObjectKey(job.canonical.revision, page.route)
592592
const snapshot: WordPressPageSnapshot = { schema: PUBLISHED_PAGE_SCHEMA, canonicalRevision: job.canonical.revision, route: page.route, status: page.status, statusText: page.statusText, headers: page.headers, body: page.body }
@@ -1091,12 +1091,6 @@ async function runNextCronEvent(runtime: Runtime): Promise<{ executed: false } |
10911091
return { executed: true, hook: event.hook, timestamp: event.timestamp!, canonicalChanges: readCanonicalChanges(runtime.php), publicationChanges: readPublicationChanges(runtime.php) }
10921092
}
10931093

1094-
async function runtimeSiteOrigin(runtime: Runtime): Promise<string> {
1095-
const output = (await runtime.php.run({ code: "<?php require '/wordpress/wp-load.php'; echo get_option('home');" })).text.trim()
1096-
const url = new URL(output)
1097-
return url.origin
1098-
}
1099-
11001094
async function health(runtime: Runtime): Promise<Response> {
11011095
const phpVersion = (await runtime.php.run({ code: "<?php echo PHP_VERSION;" })).text.trim()
11021096
return cloudflareRuntimeHealthResponse({ schema: CLOUDFLARE_RUNTIME_HEALTH_SCHEMA, marker: CLOUDFLARE_RUNTIME_HEALTH_MARKER, wordpressVersion: runtime.wordpressVersion, phpVersion, runtime: { backend: "wordpress-playground", environment: "wordpress" }, evidence: { initialization: "completed", execution: "completed", initializationScope: "isolate" } })

tests/cloudflare-runtime.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,10 @@ test("Cloudflare runtime injects composable coordinators without moving PHP out
402402
assert.match(worker, /coordinator\.committed\(candidate\.coordinatorVersion\)/)
403403
assert.match(worker, /\.list\(\{ prefix: `\$\{R2_PUBLICATION_JOB_PREFIX\}\/`, limit: 16 \}\)/)
404404
assert.match(worker, /canonicalVersion: job\.coordinatorVersion/)
405-
assert.match(worker, /await runtimeSiteOrigin\(runtime\)/)
405+
const publicationDrain = worker.slice(worker.indexOf("async function drainNextPublicationJob"), worker.indexOf("async function compilePublicationRoutes"))
406+
assert.match(publicationDrain, /bootRuntime\(env\.WORDPRESS_STATE_BUCKET, job\.canonical, SITE_URL/)
407+
assert.match(publicationDrain, /compilePublicationRoutes\(runtime, \[route\], SITE_URL\)/)
408+
assert.doesNotMatch(worker, /runtimeSiteOrigin|require '\/wordpress\/wp-load\.php'; echo get_option\('home'\)/)
406409
assert.match(worker, /await enqueuePublicationJob\(env\.WORDPRESS_STATE_BUCKET, lease, next, currentPublication, publicationChanges\)/)
407410
assert.ok(coordinatedRequest.indexOf("enqueuePublicationJob") < coordinatedRequest.indexOf("commitLease"))
408411
assert.doesNotMatch(coordinatedRequest, /compilePublicationRoutes\(runtime/)

0 commit comments

Comments
 (0)