You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue #1887 describes a gap: there is no supported way for a request-free handler (a Cloudflare Queue consumer, a custom scheduled() handler) to reach the EmDash runtime and invoke a plugin route.
The common pattern is to move slow work out of a content hook into a queue — but the consumer then needs to call back into the plugin (plugin storage, ctx.media.upload, ctx.content.update) to finish the job, and handlePluginApiRoute is only reachable through locals.emdash on a real HTTP request. The SELF.fetch() workaround fails too: a cookieless self-request gets the limitedlocals.emdash without handlePluginApiRoute.
Proposal
Export a small request-free accessor from emdash/middleware, built on the exact plumbing runScheduledTasks (plugin cron) already uses:
Not a new mechanism. It reuses the internal getConfig() → getRuntime() → createRequestScopedDb() → runWithContext() path that powers the Cron Trigger sweep, refactored into a shared helper. Connection-backed adapters (Postgres over Hyperdrive) get an event-scoped connection that is committed and closed after the callback; stateless adapters (D1, Node SQLite) use the singleton as before.
Trusted, server-only. The callback gets the raw runtime with no auth/CSRF checks — the same trust level plugin cron already has. Documented accordingly.
isWrite: true for the event scope, so queue jobs route to the primary.
I have a working implementation with tests and docs; opening a PR referencing this discussion and #1887.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem
Issue #1887 describes a gap: there is no supported way for a request-free handler (a Cloudflare Queue consumer, a custom
scheduled()handler) to reach the EmDash runtime and invoke a plugin route.The common pattern is to move slow work out of a content hook into a queue — but the consumer then needs to call back into the plugin (plugin storage,
ctx.media.upload,ctx.content.update) to finish the job, andhandlePluginApiRouteis only reachable throughlocals.emdashon a real HTTP request. TheSELF.fetch()workaround fails too: a cookieless self-request gets the limitedlocals.emdashwithouthandlePluginApiRoute.Proposal
Export a small request-free accessor from
emdash/middleware, built on the exact plumbingrunScheduledTasks(plugin cron) already uses:Usage from a queue consumer:
Design points:
getConfig() → getRuntime() → createRequestScopedDb() → runWithContext()path that powers the Cron Trigger sweep, refactored into a shared helper. Connection-backed adapters (Postgres over Hyperdrive) get an event-scoped connection that is committed and closed after the callback; stateless adapters (D1, Node SQLite) use the singleton as before.isWrite: truefor the event scope, so queue jobs route to the primary.I have a working implementation with tests and docs; opening a PR referencing this discussion and #1887.
All reactions