Skip to content

Commit

Permalink
feat(spell): update to new mailbox [NET-505] (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
justprosh authored Jul 14, 2023
1 parent 453470d commit 15f1921
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ particle-execution = { path = "particle-execution" }
system-services = { path = "crates/system-services" }

# spell
fluence-spell-dtos = "=0.5.15"
fluence-spell-distro = "=0.5.15"
fluence-spell-dtos = "=0.5.16"
fluence-spell-distro = "=0.5.16"

# marine
fluence-app-service = {version = "=0.26.4-feat-wasm-backend-interface-update-b3cf050-636-1.0", registry = "fluence"}
Expand Down
8 changes: 4 additions & 4 deletions crates/nox-tests/tests/spells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ async fn spell_timer_trigger_mailbox_test() {
(seq
(seq
(call %init_peer_id% ("getDataSrv" "spell_id") [] spell_id)
(call %init_peer_id% (spell_id "list_pop_string") ["trigger_mailbox"] trigger)
(call %init_peer_id% (spell_id "pop_mailbox") [] trigger)
)
(seq
(call %init_peer_id% ("json" "parse") [trigger.$.str] obj)
Expand Down Expand Up @@ -945,7 +945,7 @@ async fn spell_connection_pool_trigger_mailbox_test() {
(seq
(call %init_peer_id% ("getDataSrv" "spell_id") [] spell_id)
(seq
(call %init_peer_id% (spell_id "list_pop_string") ["trigger_mailbox"] trigger)
(call %init_peer_id% (spell_id "pop_mailbox") [] trigger)
(call %init_peer_id% ("run-console" "print") ["pop mailbox, trigger:" trigger])
)
)
Expand Down Expand Up @@ -1102,7 +1102,7 @@ async fn spell_update_config() {
r#"(seq
(seq
(call %init_peer_id% ("getDataSrv" "spell_id") [] spell_id)
(call %init_peer_id% (spell_id "list_pop_string") ["trigger_mailbox"] result)
(call %init_peer_id% (spell_id "pop_mailbox") [] result)
)
(call "{}" ("return" "") [result])
)"#,
Expand Down Expand Up @@ -1194,7 +1194,7 @@ async fn spell_update_config_stopped_spell() {
r#"(seq
(seq
(call %init_peer_id% ("getDataSrv" "spell_id") [] spell_id)
(call %init_peer_id% (spell_id "list_pop_string") ["trigger_mailbox"] result)
(call %init_peer_id% (spell_id "pop_mailbox") [] result)
)
(call "{}" ("return" "") [result])
)"#,
Expand Down
25 changes: 21 additions & 4 deletions sorcerer/src/script_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,32 @@ impl Sorcerer {
let func_outcome = self.services.call_function(
worker_id,
&event.spell_id,
"list_push_string",
vec![json!("trigger_mailbox"), json!(serialized_event)],
"push_mailbox",
vec![json!(serialized_event)],
None,
worker_id,
self.spell_script_particle_ttl,
);

process_func_outcome::<UnitValue>(func_outcome, &event.spell_id, "list_push_string")
.map(drop)
match process_func_outcome::<UnitValue>(func_outcome, &event.spell_id, "push_mailbox") {
Ok(_) => Ok(()),
Err(err) => {
log::warn!("Error on push_mailbox for spell {}: {}. Trying a fallback with list_push_string", event.spell_id, err);

// fallback for older spell versions
let func_outcome = self.services.call_function(
worker_id,
&event.spell_id,
"list_push_string",
vec![json!("trigger_mailbox"), json!(serialized_event)],
None,
worker_id,
self.spell_script_particle_ttl,
);
process_func_outcome::<UnitValue>(func_outcome, &event.spell_id, "list_push_string")
.map(drop)
}
}
}

pub async fn execute_script(&self, event: TriggerEvent) {
Expand Down

0 comments on commit 15f1921

Please sign in to comment.