Skip to content

Commit 9521a40

Browse files
committed
feat: invalidate warm cache on env changes, upgrade runtime-v8 to v0.13.7
Add env_updated_at to WorkerWithBindings (max updated_at from binding rows) and pass it through to PinnedExecuteRequest for warm cache invalidation. Switch runtime-v8 from local path to published v0.13.7, remove [patch.crates-io].
1 parent 9f547d0 commit 9521a40

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "openworkers-runner"
3-
version = "0.13.9"
3+
version = "0.13.10"
44
edition = "2024"
55
license = "MIT"
66
default-run = "openworkers-runner"
@@ -62,7 +62,7 @@ openworkers-core = { git = "https://github.com/openworkers/openworkers-core", ta
6262
openworkers-transform = { git = "https://github.com/openworkers/openworkers-transform", tag = "v0.1.0" }
6363

6464
# Runtime backend (v8 only for now, others require older version of core)
65-
openworkers-runtime-v8 = { git = "https://github.com/openworkers/openworkers-runtime-v8", tag = "v0.13.6", optional = true, features = ["ptrcomp"] }
65+
openworkers-runtime-v8 = { git = "https://github.com/openworkers/openworkers-runtime-v8", tag = "v0.13.7", optional = true, features = ["ptrcomp"] }
6666

6767
# WASM runtime (optional)
6868
# openworkers-runtime-wasm = { path = "../openworkers-runtime-wasm", optional = true }

src/store.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ pub struct WorkerWithBindings {
167167
pub env: HashMap<String, String>,
168168
/// All bindings (vars, secrets, and resource bindings)
169169
pub bindings: Vec<Binding>,
170+
/// Timestamp of most recent environment change (Unix epoch seconds).
171+
/// Used by the warm cache to detect stale bindings.
172+
pub env_updated_at: Option<i64>,
170173
}
171174

172175
impl From<WorkerData> for WorkerWithBindings {
@@ -191,6 +194,7 @@ impl From<WorkerData> for WorkerWithBindings {
191194
version: data.version,
192195
env,
193196
bindings,
197+
env_updated_at: None,
194198
}
195199
}
196200
}
@@ -256,6 +260,7 @@ struct BindingRow {
256260
key: String,
257261
value: Option<String>,
258262
binding_type: BindingType,
263+
updated_at_epoch: Option<i64>,
259264
}
260265

261266
/// Get worker with full binding configs
@@ -318,7 +323,8 @@ pub async fn get_worker_with_bindings(
318323
SELECT
319324
V.key,
320325
V.value,
321-
V.type as binding_type
326+
V.type as binding_type,
327+
EXTRACT(EPOCH FROM V.updated_at)::bigint as updated_at_epoch
322328
FROM workers AS W
323329
LEFT JOIN projects AS P ON W.project_id = P.id
324330
JOIN environment_values AS V ON V.environment_id = COALESCE(P.environment_id, W.environment_id) AND V.user_id = W.user_id
@@ -340,8 +346,14 @@ pub async fn get_worker_with_bindings(
340346
// Convert rows to Binding enum, fetching configs as needed
341347
let mut bindings = Vec::new();
342348
let mut env = HashMap::new();
349+
let mut env_updated_at: Option<i64> = None;
343350

344351
for row in binding_rows {
352+
// Track the most recent update timestamp across all binding rows
353+
if let Some(epoch) = row.updated_at_epoch {
354+
env_updated_at = Some(env_updated_at.map_or(epoch, |prev: i64| prev.max(epoch)));
355+
}
356+
345357
match row.binding_type {
346358
BindingType::Var => {
347359
if let Some(value) = row.value {
@@ -421,11 +433,12 @@ pub async fn get_worker_with_bindings(
421433
}
422434

423435
tracing::debug!(
424-
"worker found: id: {}, version: {}, bindings: {}, type: {}",
436+
"worker found: id: {}, version: {}, bindings: {}, type: {}, env_updated_at: {:?}",
425437
short_id(&basic.id),
426438
basic.version,
427439
bindings.len(),
428-
basic.code_type
440+
basic.code_type,
441+
env_updated_at,
429442
);
430443

431444
Some(WorkerWithBindings {
@@ -437,6 +450,7 @@ pub async fn get_worker_with_bindings(
437450
version: basic.version,
438451
env,
439452
bindings,
453+
env_updated_at,
440454
})
441455
}
442456

src/task_executor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ pub async fn execute_task_await_v8_pooled(
221221
ops: components.ops,
222222
task,
223223
on_warm_hit: Some(on_warm_hit),
224+
env_updated_at: config.worker_data.env_updated_at,
224225
},
225226
)
226227
.await

0 commit comments

Comments
 (0)