File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33use std:: fs;
44use std:: path:: Path ;
5+ use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
56use std:: time:: SystemTime ;
67
78use serde_json:: Value ;
@@ -81,15 +82,19 @@ pub(super) fn parse_json_file(path: &Path) -> Result<(), String> {
8182 Ok ( ( ) )
8283}
8384
84- /// Generate a unique `doctor-<pid>-<micros>` id for JSON command envelopes.
85+ /// Generate a unique `doctor-<pid>-<micros>-<sequence> ` id for JSON command envelopes.
8586pub ( super ) fn new_id ( ) -> String {
87+ static NEXT_ID : AtomicU64 = AtomicU64 :: new ( 0 ) ;
88+ let sequence = NEXT_ID . fetch_add ( 1 , Ordering :: Relaxed ) ;
89+
8690 format ! (
87- "doctor-{}-{}" ,
91+ "doctor-{}-{}-{} " ,
8892 std:: process:: id( ) ,
8993 SystemTime :: now( )
9094 . duration_since( SystemTime :: UNIX_EPOCH )
9195 . map( |d| d. as_micros( ) )
92- . unwrap_or( 0 )
96+ . unwrap_or( 0 ) ,
97+ sequence
9398 )
9499}
95100
You can’t perform that action at this time.
0 commit comments