Skip to content

Commit 805757e

Browse files
authored
Merge branch 'master' into kim/paths/fdatasync-pidfile
2 parents 6577ab6 + 458eac8 commit 805757e

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,15 +887,16 @@ jobs:
887887
const targetRepo = process.env.TARGET_REPO;
888888
// Use the ref for pull requests because the head sha is brittle (github does some extra dance where it merges in master).
889889
const publicRef = (context.eventName === 'pull_request') ? context.payload.pull_request.head.ref : context.sha;
890+
const publicPrNumber = context.payload.pull_request?.number ?? context.payload.inputs?.pr_number;
890891
const preDispatch = new Date().toISOString();
891-
892+
892893
// Dispatch the workflow in the target repository
893894
await github.rest.actions.createWorkflowDispatch({
894895
owner: targetOwner,
895896
repo: targetRepo,
896897
workflow_id: workflowId,
897898
ref: targetRef,
898-
inputs: { public_ref: publicRef }
899+
inputs: { public_ref: publicRef, public_pr_number: String(publicPrNumber) }
899900
});
900901
901902
const sleep = (ms) => new Promise(r => setTimeout(r, ms));

crates/client-api-messages/src/energy.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ pub struct EnergyQuanta {
1616
impl EnergyQuanta {
1717
pub const ZERO: Self = EnergyQuanta { quanta: 0 };
1818

19+
// per the comment on [`FunctionBudget::DEFAULT_BUDGET`]: 1 second of wasm runtime is roughtly 2 TeV
20+
pub const PER_EXECUTION_SEC: Self = Self::new(2_000_000_000_000);
21+
pub const PER_EXECUTION_NANOSEC: Self = Self::new(Self::PER_EXECUTION_SEC.get() / 1_000_000_000);
22+
1923
#[inline]
20-
pub fn new(quanta: u128) -> Self {
24+
pub const fn new(quanta: u128) -> Self {
2125
Self { quanta }
2226
}
2327

2428
#[inline]
25-
pub fn get(&self) -> u128 {
29+
pub const fn get(&self) -> u128 {
2630
self.quanta
2731
}
2832

crates/core/src/host/v8/budget.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use core::ptr;
1313
use core::sync::atomic::Ordering;
1414
use core::time::Duration;
1515
use core::{ffi::c_void, sync::atomic::AtomicBool};
16-
use spacetimedb_client_api_messages::energy::FunctionBudget;
16+
use spacetimedb_client_api_messages::energy::{EnergyQuanta, FunctionBudget};
1717
use std::sync::Arc;
1818
use v8::{Isolate, IsolateHandle};
1919

@@ -118,7 +118,12 @@ fn budget_to_duration(_budget: FunctionBudget) -> Duration {
118118
/// Returns [`EnergyStats`] for a reducer given its `budget`
119119
/// and the `duration` it took to execute.
120120
pub(super) fn energy_from_elapsed(budget: FunctionBudget, duration: Duration) -> EnergyStats {
121-
let used = duration_to_budget(duration);
121+
let used = duration.as_nanos() * EnergyQuanta::PER_EXECUTION_NANOSEC.get();
122+
// in order for duration_nanos * ev_per_ns >= u64::MAX:
123+
// duration_nanos >= u64::MAX / ev_per_ns
124+
// duration_nanos >= (9223372036854775 ns = 106.75 days)
125+
// so it's unlikely we'll have to worry about it
126+
let used = FunctionBudget::new(u64::try_from(used).unwrap_or(u64::MAX));
122127
let remaining = budget - used;
123128
EnergyStats { budget, remaining }
124129
}

0 commit comments

Comments
 (0)