Skip to content

Commit

Permalink
fix: allow setting static patterns when creating a user worker (#471)
Browse files Browse the repository at this point in the history
* fix: allow setting static patterns when creating a user worker

* fix: clippy

* fix: make static_patterns optional

* formatting

* Trigger Build
  • Loading branch information
laktek authored Jan 9, 2025
1 parent 6246a6f commit d2c21c1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
5 changes: 3 additions & 2 deletions crates/base/src/worker/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ impl WorkerPool {
maybe_jsx_import_source_config,
maybe_s3_fs_config,
maybe_tmp_fs_config,
static_patterns,
..
} = worker_options;

Expand All @@ -381,7 +382,7 @@ impl WorkerPool {
maybe_module_code,
maybe_entrypoint,
maybe_decorator,
static_patterns: vec![],
static_patterns,

maybe_jsx_import_source_config,
maybe_s3_fs_config,
Expand Down Expand Up @@ -714,7 +715,7 @@ pub async fn create_user_worker_pool(
None => break,
Some(UserWorkerMsgs::Create(worker_options, tx)) => {
worker_pool.create_user_worker(WorkerContextInitOpts {
static_patterns: static_patterns.clone(),
static_patterns: [worker_options.static_patterns, static_patterns.clone()].concat(),
maybe_jsx_import_source_config: {
if worker_options.maybe_jsx_import_source_config.is_some() {
worker_options.maybe_jsx_import_source_config
Expand Down
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"./crates/base/test_cases"
],
"fmt": {
"useTabs": true,
"useTabs": false,
"lineWidth": 100,
"indentWidth": 4,
"singleQuote": true,
Expand All @@ -14,4 +14,4 @@
"npm:@meowmeow/foobar": "npm:is-odd",
"openai": "npm:openai"
}
}
}
4 changes: 4 additions & 0 deletions examples/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ Deno.serve(async (req: Request) => {
//
const cpuTimeSoftLimitMs = 10000;
const cpuTimeHardLimitMs = 20000;
const staticPatterns = [
'./examples/**/*.html',
];

return await EdgeRuntime.userWorkers.create({
servicePath,
Expand All @@ -143,6 +146,7 @@ Deno.serve(async (req: Request) => {
netAccessDisabled,
cpuTimeSoftLimitMs,
cpuTimeHardLimitMs,
staticPatterns,
// maybeEszip,
// maybeEntrypoint,
// maybeModuleCode,
Expand Down
3 changes: 3 additions & 0 deletions examples/serve-html/bar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>
<h1>Bar</h1>
</html>
3 changes: 3 additions & 0 deletions examples/serve-html/foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>
<h1>Foo</h1>
</html>
9 changes: 9 additions & 0 deletions examples/serve-html/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { join } from 'https://deno.land/std/path/mod.ts';

Deno.serve(async (req) => {
if (req.url.endsWith('/foo')) {
return new Response(await Deno.readTextFile(join(import.meta.dirname, 'foo.html')));
} else {
return new Response(await Deno.readTextFile(join(import.meta.dirname, 'bar.html')));
}
});
5 changes: 4 additions & 1 deletion ext/workers/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ pub struct UserWorkerCreateOptions {
tmp_fs_config: Option<TmpFsConfig>,

context: Option<JsonMap>,
#[serde(default)]
static_patterns: Vec<String>,
}

#[op2(async)]
Expand Down Expand Up @@ -131,6 +133,7 @@ pub async fn op_user_worker_create(
tmp_fs_config: maybe_tmp_fs_config,

context,
static_patterns,
} = opts;

let user_worker_options = WorkerContextInitOpts {
Expand Down Expand Up @@ -165,7 +168,7 @@ pub async fn op_user_worker_create(
}
}),

static_patterns: vec![],
static_patterns,
import_map_path,
timing: None,

Expand Down

0 comments on commit d2c21c1

Please sign in to comment.