#Running one time scripts in context of the configured worker

7 messages · Page 1 of 1 (latest)

scenic creek
#

I would like to run a script on my local machine which would hook into the context of my worker which is already configured on Cloudflare and then perform any operation in that context, e.g. using D1, KV directly without having to actually run a worker with a fetch handler and then do a an HTTP request to achieve essentially the same.

You could think about it as simply running the node command with a file in your project which has access to the whole context of the project (e.g. databases, env variables etc). A similar approach from other language/frameworks are Django management commands.

The way I imagine this is simply running wrangler dev and instead of launching a worker service (which essentially runs as an HTTP service) it would execute a worker "script" which runs once and then exits. Is this possible in workers and if so how?

plucky talon
scenic creek
#

Thanks. Haven't considered looking for a wrangler API.
The unstable_dev name put me a off a little bit though. Is there a chance this might become obsolete in the future?

plucky talon
#

It means that there could be breaking changes between wrangler versions - though those should mostly be within the experimental part of the options

#

If it's any consolation, wrangler pages dev has been powered by it for almost a year now

scenic creek
#

👍 All right. Thank you again. Will probably move forward using the Wrangler API then.

plucky talon
#

Awesome, feel free to follow up with any questions you get