Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Nov 17, 2023
1 parent 28bed17 commit 36350b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/SlimFaas/Database/SlimDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SlimDataService(HttpClient httpClient, SimplePersistentState simple

private async Task<EndPoint> GetAndWaitForLeader()
{
var numberWaitMaximum = 10;
var numberWaitMaximum = 6;
while (cluster.Leader == null && numberWaitMaximum > 0)
{
await Task.Delay(500);
Expand All @@ -42,7 +42,8 @@ public async Task SetAsync(string key, string value)
var multipart = new MultipartFormDataContent();
multipart.Add(new StringContent(value), key);

var response = await httpClient.PostAsync(new Uri($"{GetAndWaitForLeader()}AddKeyValue"), multipart);
var endpoint = await GetAndWaitForLeader();
var response = await httpClient.PostAsync(new Uri($"{endpoint}AddKeyValue"), multipart);
if ((int)response.StatusCode >= 500)
{
throw new DataException("Error in calling SlimData HTTP Service");
Expand All @@ -58,7 +59,8 @@ public async Task HashSetAsync(string key, IDictionary<string, string> values)
multipart.Add(new StringContent(value.Value), value.Key);
}

var response = await httpClient.PostAsync(new Uri($"{GetAndWaitForLeader()}AddHashset"), multipart);
var endpoint = await GetAndWaitForLeader();
var response = await httpClient.PostAsync(new Uri($"{endpoint}AddHashset"), multipart);
if ((int)response.StatusCode >= 500)
{
throw new DataException("Error in calling SlimData HTTP Service");
Expand All @@ -72,7 +74,8 @@ public async Task<IDictionary<string, string>> HashGetAllAsync(string key) {
}

public async Task ListLeftPushAsync(string key, string field) {
var request = new HttpRequestMessage(HttpMethod.Post, new Uri($"{GetAndWaitForLeader()}ListLeftPush"));
var endpoint = await GetAndWaitForLeader();
var request = new HttpRequestMessage(HttpMethod.Post, new Uri($"{endpoint}ListLeftPush"));
var multipart = new MultipartFormDataContent();
multipart.Add(new StringContent(field), key);
request.Content = multipart;
Expand All @@ -85,7 +88,8 @@ public async Task ListLeftPushAsync(string key, string field) {

public async Task<IList<string>> ListRightPopAsync(string key, long count = 1)
{
var request = new HttpRequestMessage(HttpMethod.Post, new Uri($"{GetAndWaitForLeader()}ListRightPop"));
var endpoint = await GetAndWaitForLeader();
var request = new HttpRequestMessage(HttpMethod.Post, new Uri($"{endpoint}ListRightPop"));
var multipart = new MultipartFormDataContent();
multipart.Add(new StringContent(count.ToString()), key);

Expand Down
2 changes: 1 addition & 1 deletion src/SlimFaas/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
replicasService?.SyncDeploymentsAsync(namespace_).Wait();

var hostname = Environment.GetEnvironmentVariable("HOSTNAME");
while (replicasService?.Deployments.SlimFaas.Pods.Select(p => !string.IsNullOrEmpty(p.Ip)).Count() < 2 ||
while (replicasService?.Deployments.SlimFaas.Pods.Select(p => !string.IsNullOrEmpty(p.Ip) && p.Started == true).Count() < 3 ||
replicasService?.Deployments.SlimFaas.Pods.Any(p => p.Name == hostname) == false)
{
Console.WriteLine("Waiting for pods to be ready");
Expand Down

0 comments on commit 36350b5

Please sign in to comment.