diff --git a/BlazorCanvas/BlazorCanvas.Server/Components/Data/CanvasService.cs b/BlazorCanvas/BlazorCanvas.Server/Components/Data/CanvasService.cs index e241ca1..20c6544 100644 --- a/BlazorCanvas/BlazorCanvas.Server/Components/Data/CanvasService.cs +++ b/BlazorCanvas/BlazorCanvas.Server/Components/Data/CanvasService.cs @@ -18,6 +18,7 @@ public class CanvasService { private IRedisService _redisService; private CanvasCommand _lastCommand = new(); private List _lsComms = new(); + private Guid _id = Guid.NewGuid(); private bool _is_init = false, _is_started = false, _has_ended = false; @@ -54,11 +55,12 @@ public class CanvasService { while (!_has_ended) { if (_lsComms.Count > 0) _lsComms.Clear(); - _lsComms.AddRange(await _redisService.Consume()); + _lsComms.AddRange(await _redisService.Consume(_id.ToString())); if (_lsComms.Count == 1) Draw(_lsComms[0]); else if (_lsComms.Count > 0) Draw(_lsComms); + Task.Delay(10); } } diff --git a/BlazorCanvas/BlazorCanvas.Server/Components/Data/IRedisService.cs b/BlazorCanvas/BlazorCanvas.Server/Components/Data/IRedisService.cs index 36aa4a0..38554ab 100644 --- a/BlazorCanvas/BlazorCanvas.Server/Components/Data/IRedisService.cs +++ b/BlazorCanvas/BlazorCanvas.Server/Components/Data/IRedisService.cs @@ -8,5 +8,5 @@ public interface IRedisService { void Publish(CanvasCommand command); void Produce(CanvasCommand command); - Task> Consume(); + Task> Consume(string id); } diff --git a/BlazorCanvas/BlazorCanvas.Server/Components/Data/RedisService.cs b/BlazorCanvas/BlazorCanvas.Server/Components/Data/RedisService.cs index dd19c60..52a1c94 100644 --- a/BlazorCanvas/BlazorCanvas.Server/Components/Data/RedisService.cs +++ b/BlazorCanvas/BlazorCanvas.Server/Components/Data/RedisService.cs @@ -56,20 +56,22 @@ public class RedisService : IRedisService { public async void Produce(CanvasCommand command) { arNve[0] = new NameValueEntry("command", JsonConvert.SerializeObject(command)); - await _database.StreamAddAsync(STREAM_NAME, arNve); + _database.StreamAddAsync(STREAM_NAME, arNve); } - public async Task> Consume() { + public async Task> Consume(string id) { List lsComm = new(); CanvasCommand? comm; - var result = await _database.StreamReadGroupAsync(STREAM_NAME, GROUP_NAME, "commCon", ">"); - + var result = await _database.StreamReadGroupAsync(STREAM_NAME, GROUP_NAME, id, ">", 100); + string json = ""; foreach (var c in result) { - await _database.StreamAcknowledgeAsync(STREAM_NAME, GROUP_NAME, c.Id); + _database.StreamAcknowledgeAsync(STREAM_NAME, GROUP_NAME, c.Id); try { - string json = c.Values.FirstOrDefault(x => x.Name == "command").Value.ToString(); + json = c.Values.FirstOrDefault(x => x.Name == "command").Value.ToString(); comm = JsonConvert.DeserializeObject(json); - } catch { continue; } + } catch { + Console.WriteLine($"OH NO {json}"); + continue; } if (comm is not null) lsComm.Add(comm); } diff --git a/BlazorCanvas/BlazorCanvas.Server/Docker_Deploy.yaml b/BlazorCanvas/BlazorCanvas.Server/Docker_Deploy.yaml new file mode 100644 index 0000000..b2900a7 --- /dev/null +++ b/BlazorCanvas/BlazorCanvas.Server/Docker_Deploy.yaml @@ -0,0 +1,125 @@ +# First, add the API +apiVersion: apps/v1 +# This will be the deployment setup +kind: Deployment +metadata: + # Name your Deployment here + name: blazorcanvas + labels: + # label your deployment + app: BlazorCanvas-etc +spec: + # The number of pods/replicas to run + replicas: 2 + selector: + matchLabels: + # selector to match the pod + app: BlazorCanvas-etc + template: + metadata: + labels: + # label your pod + app: BlazorCanvas-etc + spec: + containers: + # Add the container name for Kubernetes + - name: blazorcanvas + # Add the local image name + image: blazorcanvasserver:latest + # never pull the image policy + imagePullPolicy: Never + ports: + # port for running the container, le port sur lequel l'application du conteneur roule + - containerPort: 8080 + - containerPort: 8081 + # First, add the API +--- +apiVersion: apps/v1 +# This will be the deployment setup +kind: Deployment +metadata: + # Name your Deployment here + name: francis-redis + labels: + # label your deployment + app: redis-app +spec: + # The number of pods/replicas to run + replicas: 1 + selector: + matchLabels: + # selector to match the pod + app: redis-app + template: + metadata: + labels: + # label your pod + app: redis-app + spec: + containers: + # Add the container name for Kubernetes + # Cette image est téléchargée en partant BlazorCanvas.AppHost et doit passer par minikube image load. + - name: redis + # Add the local image name + image: redis:latest + # never pull the image policy + imagePullPolicy: IfNotPresent + ports: + # ports for running the container, le port sur lequel l'application du conteneur roule + - containerPort: 6379 + env: + - name: "REDIS_ARGS" + value: "--appendonly yes --appendfsync everysec" +--- +# First, add the Service API +apiVersion: v1 +# This will be the Service setup +kind: Service +metadata: + # Your service name + name: francis-redis +spec: + selector: + # selector that matches the pod + app: redis-app + # type of service + type: LoadBalancer + ports: + - protocol: TCP + # port for exposing the service + port: 6379 + # portfor exposing the pod + targetPort: 6379 + # port for exposing the node + nodePort: 31121 +--- +# First, add the Service API +apiVersion: v1 +# This will be the Service setup +kind: Service +metadata: + # Your service name + name: blazorcanvas-srv +spec: + selector: + # selector that matches the pod + app: BlazorCanvas-etc + # type of service + type: LoadBalancer + ports: + - protocol: TCP + name: "http" + # port for exposing the service + port: 8080 + # portfor exposing the pod + targetPort: 8080 + # port for exposing the node + nodePort: 31122 + - protocol: TCP + name: "https" + # port for exposing the service + port: 8081 + # portfor exposing the pod + targetPort: 8081 + # port for exposing the node + nodePort: 31123 \ No newline at end of file diff --git a/BlazorCanvas/BlazorCanvas.Server/appsettings.json b/BlazorCanvas/BlazorCanvas.Server/appsettings.json index 06b5635..f4e3bbe 100644 --- a/BlazorCanvas/BlazorCanvas.Server/appsettings.json +++ b/BlazorCanvas/BlazorCanvas.Server/appsettings.json @@ -7,6 +7,6 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "cache": "host.docker.internal" + "cache": "francis-redis" } }