@@ -165,72 +165,36 @@ impl FromValue for Timestamp {
165165 }
166166}
167167
168+ /// A stable, per-instance fingerprint for a worker, generated as a random UUID at creation time.
169+ /// Globally unique across recreations of the same agent ID.
168170#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
169- #[ cfg_attr( feature = "full" , derive( desert_rust:: BinaryCodec ) ) ]
170- #[ cfg_attr( feature = "full" , desert( evolution( ) ) ) ]
171- #[ serde( tag = "type" , content = "value" , rename_all = "camelCase" ) ]
172- pub enum AgentFingerprint {
173- /// Randomly generated at worker creation time. Globally unique across recreations.
174- Uuid ( Uuid ) ,
175- /// Fallback for workers created before `AgentFingerprint` was introduced.
176- /// The timestamp is the worker's `created_at` from the oplog `Create` entry.
177- Timestamp ( Timestamp ) ,
178- }
171+ #[ cfg_attr(
172+ feature = "full" ,
173+ derive(
174+ desert_rust:: BinaryCodec ,
175+ golem_wasm_derive:: IntoValue ,
176+ golem_wasm_derive:: FromValue ,
177+ )
178+ ) ]
179+ #[ cfg_attr( feature = "full" , desert( transparent) ) ]
180+ #[ serde( transparent) ]
181+ pub struct AgentFingerprint ( pub Uuid ) ;
179182
180- impl Display for AgentFingerprint {
181- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
182- match self {
183- AgentFingerprint :: Uuid ( u) => write ! ( f, "uuid:{u}" ) ,
184- AgentFingerprint :: Timestamp ( t) => write ! ( f, "ts:{t}" ) ,
185- }
183+ impl Default for AgentFingerprint {
184+ fn default ( ) -> Self {
185+ Self :: new ( )
186186 }
187187}
188188
189- #[ cfg( feature = "full" ) ]
190- impl golem_wasm:: IntoValue for AgentFingerprint {
191- fn into_value ( self ) -> golem_wasm:: Value {
192- match self {
193- AgentFingerprint :: Uuid ( u) => {
194- golem_wasm:: Value :: Variant {
195- case_idx : 0 ,
196- case_value : Some ( Box :: new ( u. into_value ( ) ) ) ,
197- }
198- }
199- AgentFingerprint :: Timestamp ( ts) => golem_wasm:: Value :: Variant {
200- case_idx : 1 ,
201- case_value : Some ( Box :: new ( golem_wasm:: Value :: U64 ( ts. to_millis ( ) ) ) ) ,
202- } ,
203- }
204- }
205-
206- fn get_type ( ) -> golem_wasm:: analysis:: AnalysedType {
207- use golem_wasm:: analysis:: analysed_type;
208- analysed_type:: variant ( vec ! [
209- analysed_type:: case( "uuid" , Uuid :: get_type( ) ) ,
210- analysed_type:: case( "timestamp" , u64 :: get_type( ) ) ,
211- ] )
189+ impl AgentFingerprint {
190+ pub fn new ( ) -> Self {
191+ AgentFingerprint ( Uuid :: now_v7 ( ) )
212192 }
213193}
214194
215- #[ cfg( feature = "full" ) ]
216- impl golem_wasm:: FromValue for AgentFingerprint {
217- fn from_value ( value : golem_wasm:: Value ) -> Result < Self , String > {
218- match value {
219- golem_wasm:: Value :: Variant {
220- case_idx : 0 ,
221- case_value : Some ( inner) ,
222- } => Ok ( AgentFingerprint :: Uuid ( Uuid :: from_value ( * inner) ?) ) ,
223- golem_wasm:: Value :: Variant {
224- case_idx : 1 ,
225- case_value : Some ( inner) ,
226- } => match * inner {
227- golem_wasm:: Value :: U64 ( millis) => {
228- Ok ( AgentFingerprint :: Timestamp ( Timestamp :: from ( millis) ) )
229- }
230- other => Err ( format ! ( "Expected U64 for Timestamp fingerprint, got {other:?}" ) ) ,
231- } ,
232- other => Err ( format ! ( "Expected Variant for AgentFingerprint, got {other:?}" ) ) ,
233- }
195+ impl Display for AgentFingerprint {
196+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
197+ write ! ( f, "{}" , self . 0 )
234198 }
235199}
236200
0 commit comments