Skip to content

Commit

Permalink
feat: implement timers
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Aug 17, 2022
1 parent 2e24440 commit e5915b6
Show file tree
Hide file tree
Showing 13 changed files with 525 additions and 113 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ env_logger = "0.9"
futures = "0.3"
humantime = "2"
humantime-serde = "1"
indexmap = "1.9"
json-patch = { version = "0.2", default-features = false }
jsonschema = "0.16"
log = "0.4"
Expand All @@ -29,7 +30,7 @@ postgres-types = "0.2"
rdkafka = { version = "0.28", features = ["sasl", "ssl"] }
rustls = "0.20"
rustls-native-certs = "0.6"
schemars = { version = "0.8", features = ["bytes", "chrono"] }
schemars = { version = "0.8", features = ["bytes", "chrono", "indexmap"] }
serde = "1"
serde_json = "1"
thiserror = "1"
Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod machine;
pub mod model;
pub mod notifier;
pub mod processor;
mod schemars;
pub mod service;
pub mod storage;
pub mod version;
Expand Down
15 changes: 9 additions & 6 deletions core/src/machine/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ const KEY_WAKER: &str = "waker";
/// TODO: consider keeping the runtime for this run.
pub async fn run(
name: String,
script: String,
script: &str,
current_thing: Arc<Thing>,
new_thing: Thing,
new_thing: &Thing,
opts: DenoOptions,
) -> anyhow::Result<Outgoing> {
let script = script.to_string();
let new_thing = new_thing.clone();

let thing = Handle::current()
.spawn_blocking(move || {
// disable some operations
Expand Down Expand Up @@ -62,7 +65,7 @@ pub async fn run(
isolate.terminate_execution();
});

set_context(&mut runtime, &current_thing, new_thing)?;
set_context(&mut runtime, &current_thing, &new_thing)?;

// FIXME: take return value
let _ = runtime.execute_script(&name, &script)?;
Expand All @@ -81,7 +84,7 @@ pub async fn run(
fn set_context(
runtime: &mut JsRuntime,
current_state: &Thing,
new_state: Thing,
new_state: &Thing,
) -> anyhow::Result<()> {
let global = runtime.global_context();
let scope = &mut runtime.handle_scope();
Expand Down Expand Up @@ -138,7 +141,7 @@ fn extract_context(runtime: &mut JsRuntime) -> anyhow::Result<Outgoing> {
}
};

let log = {
let logs = {
let key = serde_v8::to_v8(&mut scope, KEY_LOGS)?;
match global.get(scope, key) {
Some(value) => serde_v8::from_v8(scope, value)?,
Expand All @@ -157,7 +160,7 @@ fn extract_context(runtime: &mut JsRuntime) -> anyhow::Result<Outgoing> {
Ok(Outgoing {
new_thing,
outbox,
log,
logs,
waker,
})
}
Expand Down
Loading

0 comments on commit e5915b6

Please sign in to comment.