Skip to content

Commit

Permalink
Make client join shards and return
Browse files Browse the repository at this point in the history
Instead of running a loop forever, have the client join threads when
they end.

This is currently a poor way of having the client eventually end, but
for now it's a duck-tape solution, as when one shard completely fails to
reboot it's an indicator of a larger issue (invalidated authentication,
intermittent network issues, etc.)
  • Loading branch information
Zeyla Hellyer committed Jun 6, 2017
1 parent 8b10285 commit 175d3a3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/client/mod.rs
Expand Up @@ -937,6 +937,8 @@ impl Client {
let shards_index = shard_data.map_or(0, |x| x[0]);
let shards_total = shard_data.map_or(1, |x| x[1] + 1);

let mut threads = vec![];

for shard_number in shards_index..shards_total {
let shard_info = shard_data.map(|s| [shard_number, s[2]]);

Expand Down Expand Up @@ -993,9 +995,9 @@ impl Client {
}
}};

thread::spawn(move || {
threads.push(thread::spawn(move || {
monitor_shard(monitor_info);
});
}));
},
Err(why) => warn!("Error starting shard {:?}: {:?}", shard_info, why),
}
Expand All @@ -1006,9 +1008,11 @@ impl Client {
thread::sleep(Duration::from_secs(5));
}

loop {
thread::sleep(Duration::from_secs(1));
for thread in threads {
let _ = thread.join();
}

Ok(())
}
}

Expand Down

0 comments on commit 175d3a3

Please sign in to comment.