Implement DurableOrchestrationContext.new_guid.
This commit implements `DurableOrchestrationContext.new_guid`.
This commit is contained in:
parent
42abd01ba2
commit
68e3730d2a
|
@ -85,10 +85,12 @@ dependencies = [
|
|||
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tonic 0.1.0-alpha.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -1467,6 +1469,11 @@ dependencies = [
|
|||
"opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha1"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "signalr-example"
|
||||
version = "0.1.0"
|
||||
|
@ -2021,6 +2028,14 @@ dependencies = [
|
|||
"percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.1"
|
||||
|
@ -2275,6 +2290,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2"
|
||||
"checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573"
|
||||
"checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68"
|
||||
"checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
|
||||
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||
"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6"
|
||||
"checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
@ -2325,6 +2341,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||
"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
|
||||
"checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
|
||||
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||
"checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e"
|
||||
|
|
|
@ -30,6 +30,8 @@ ctrlc = "3.1.3"
|
|||
backtrace = "0.3.39"
|
||||
fs_extra = "1.1.0"
|
||||
semver = "0.9.0"
|
||||
sha1 = "0.6.0"
|
||||
uuid = { version = "0.8.1", features = ["v5"] }
|
||||
|
||||
[features]
|
||||
unstable = ["azure-functions-codegen/unstable", "azure-functions-shared/unstable"]
|
||||
|
|
|
@ -78,6 +78,12 @@ impl DurableOrchestrationContext {
|
|||
self.state.borrow_mut().set_custom_status(status.into());
|
||||
}
|
||||
|
||||
/// Create a new deterministic GUID suitable for use with orchestrations.
|
||||
pub fn new_guid(&self) -> uuid::Uuid {
|
||||
let mut state = self.state.borrow_mut();
|
||||
state.new_guid(&self.instance_id)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn state(&self) -> Rc<RefCell<OrchestrationState>> {
|
||||
self.state.clone()
|
||||
|
|
|
@ -2,6 +2,8 @@ use crate::durable::{Action, EventType, HistoryEvent};
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::Serialize;
|
||||
use serde_json::{to_string, Value};
|
||||
use sha1::Sha1;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -19,6 +21,7 @@ pub struct OrchestrationState {
|
|||
result: ExecutionResult,
|
||||
started_index: usize,
|
||||
completed_index: Option<usize>,
|
||||
guid_counter: u32,
|
||||
}
|
||||
|
||||
impl OrchestrationState {
|
||||
|
@ -38,6 +41,7 @@ impl OrchestrationState {
|
|||
result: ExecutionResult::default(),
|
||||
started_index,
|
||||
completed_index,
|
||||
guid_counter: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,6 +177,28 @@ impl OrchestrationState {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_guid(&mut self, instance_id: &str) -> uuid::Uuid {
|
||||
const GUID_NAMESPACE: &str = "9e952958-5e33-4daf-827f-2fa12937b875";
|
||||
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.update(
|
||||
format!(
|
||||
"{}_{}_{}",
|
||||
instance_id,
|
||||
self.current_time().to_string(),
|
||||
self.guid_counter
|
||||
)
|
||||
.as_bytes(),
|
||||
);
|
||||
|
||||
self.guid_counter += 1;
|
||||
|
||||
Uuid::new_v5(
|
||||
&Uuid::parse_str(GUID_NAMESPACE).expect("failed to parse namespace GUID"),
|
||||
&hasher.digest().bytes(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in New Issue