Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(all): retry and clean queue system #77

Merged
merged 139 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
645d150
feat(all): retry with dead letter queue
guillaume-chervet Sep 18, 2024
36d805a
fix test
guillaume-chervet Sep 19, 2024
e189e52
test
guillaume-chervet Oct 2, 2024
f353956
test demo
guillaume-chervet Oct 2, 2024
a51a594
test
guillaume-chervet Oct 2, 2024
ea68a0f
fix
guillaume-chervet Oct 2, 2024
2bcbf4e
fix
guillaume-chervet Oct 2, 2024
8a30f76
fix
guillaume-chervet Oct 2, 2024
7e592d5
test
guillaume-chervet Oct 2, 2024
868340c
test
guillaume-chervet Oct 2, 2024
a31b2f7
dada
guillaume-chervet Oct 2, 2024
b551e52
update
guillaume-chervet Oct 2, 2024
9be7563
fix
guillaume-chervet Oct 2, 2024
7337852
fix
guillaume-chervet Oct 2, 2024
b02c40a
fix
guillaume-chervet Oct 2, 2024
fee300d
fix
guillaume-chervet Oct 2, 2024
374438e
dqsdqs
guillaume-chervet Oct 2, 2024
f66db0d
test
guillaume-chervet Oct 2, 2024
76820f0
fix
guillaume-chervet Oct 2, 2024
ac26a2b
test
guillaume-chervet Oct 2, 2024
3038b8e
test
guillaume-chervet Oct 3, 2024
edaa5cf
fix
guillaume-chervet Oct 3, 2024
76f33f0
qdqd
guillaume-chervet Oct 3, 2024
e40c246
fix
guillaume-chervet Oct 3, 2024
00adc78
Update global.json
guillaume-chervet Oct 3, 2024
80b7604
Update Fibonacci.csproj
guillaume-chervet Oct 3, 2024
3ff62da
fix
guillaume-chervet Oct 3, 2024
a392253
qsddf
guillaume-chervet Oct 3, 2024
11f14d5
fix
guillaume-chervet Oct 3, 2024
dae5f4f
fix
guillaume-chervet Oct 3, 2024
5f6a78b
update documentation
guillaume-chervet Oct 7, 2024
25ace8b
update
guillaume-chervet Oct 7, 2024
7131f96
merge with main
guillaume-chervet Oct 17, 2024
6ee04cb
test
guillaume-chervet Nov 8, 2024
c63ece3
updae
guillaume-chervet Nov 9, 2024
15f7f51
update
guillaume-chervet Nov 11, 2024
476c574
first build
guillaume-chervet Nov 13, 2024
03d9976
fix serialization
guillaume-chervet Nov 13, 2024
8e17abe
fix
guillaume-chervet Nov 13, 2024
99c6ed0
fix
guillaume-chervet Nov 13, 2024
0f8a3fc
fix
guillaume-chervet Nov 13, 2024
d5b2f16
update
guillaume-chervet Nov 14, 2024
9e95c4a
fix
guillaume-chervet Nov 14, 2024
3aa2d21
fix
guillaume-chervet Nov 16, 2024
5e9dfd9
fix
guillaume-chervet Nov 16, 2024
a76a587
fix
guillaume-chervet Nov 16, 2024
4a488a7
test
guillaume-chervet Nov 17, 2024
23bd13e
fix
guillaume-chervet Nov 17, 2024
579d8d5
fix
guillaume-chervet Nov 17, 2024
1864219
test
guillaume-chervet Nov 17, 2024
58b386f
test
guillaume-chervet Nov 17, 2024
24bfaf9
text
guillaume-chervet Nov 17, 2024
d79c212
fix
guillaume-chervet Nov 17, 2024
f4990d0
test
guillaume-chervet Nov 17, 2024
b3d654f
fix
guillaume-chervet Nov 17, 2024
5331249
fix
guillaume-chervet Nov 17, 2024
9c8d98d
test
guillaume-chervet Nov 18, 2024
755dcd2
update
guillaume-chervet Nov 19, 2024
dccd5ff
fix test
guillaume-chervet Nov 19, 2024
f438057
test
guillaume-chervet Nov 19, 2024
83bcc27
last fix
guillaume-chervet Nov 19, 2024
c3992e8
fix
guillaume-chervet Nov 19, 2024
34f84b2
test
guillaume-chervet Nov 19, 2024
674c2c0
fix
guillaume-chervet Nov 19, 2024
445650c
test
guillaume-chervet Nov 20, 2024
c135ec2
test
guillaume-chervet Nov 20, 2024
3b6a752
test
guillaume-chervet Nov 20, 2024
adba751
update
guillaume-chervet Nov 21, 2024
4c4cf1d
fix
guillaume-chervet Nov 21, 2024
a37e207
test
guillaume-chervet Nov 21, 2024
559fa07
fix
guillaume-chervet Nov 21, 2024
711163d
fix
guillaume-chervet Nov 22, 2024
5695601
fix
guillaume-chervet Nov 23, 2024
0106607
ddd
guillaume-chervet Nov 23, 2024
6a3b971
sss
guillaume-chervet Nov 23, 2024
6fe2573
sssssss
guillaume-chervet Nov 23, 2024
92371dd
fox
guillaume-chervet Nov 24, 2024
8149515
fix
guillaume-chervet Nov 25, 2024
d7ed680
optimzation du be able to read logs
guillaume-chervet Nov 26, 2024
8428682
to be finieshed
guillaume-chervet Nov 26, 2024
0ac1cf0
fix
guillaume-chervet Nov 27, 2024
21e145f
fix
guillaume-chervet Nov 27, 2024
5199d17
f
guillaume-chervet Nov 27, 2024
98af0f9
Merge branch 'main' into feature/retry-with-deadletter-queue
guillaume-chervet Dec 10, 2024
9aa0f8f
test
guillaume-chervet Dec 12, 2024
103a40e
test
guillaume-chervet Dec 14, 2024
10f3352
test
guillaume-chervet Dec 14, 2024
18c007c
test
guillaume-chervet Dec 17, 2024
e3df9c6
test
guillaume-chervet Dec 17, 2024
ec64ab5
ss
guillaume-chervet Dec 17, 2024
d818dbe
test
guillaume-chervet Dec 17, 2024
80b09b3
test
guillaume-chervet Dec 17, 2024
757c183
test
guillaume-chervet Dec 17, 2024
dc5b1d5
test
guillaume-chervet Dec 18, 2024
67ed9b1
update
guillaume-chervet Dec 18, 2024
ad41a80
test
guillaume-chervet Dec 18, 2024
c59e405
update
guillaume-chervet Dec 18, 2024
7cff6ab
test
guillaume-chervet Dec 18, 2024
d650f60
test
guillaume-chervet Dec 19, 2024
cb248e7
test
guillaume-chervet Dec 19, 2024
f1d6246
update
guillaume-chervet Dec 19, 2024
710b151
test
guillaume-chervet Dec 19, 2024
e3de7c1
test
guillaume-chervet Dec 19, 2024
14156ce
start clean up
guillaume-chervet Dec 19, 2024
8a9a29e
test
guillaume-chervet Dec 19, 2024
f1afb10
fix
guillaume-chervet Dec 19, 2024
8e35111
clean
guillaume-chervet Dec 19, 2024
de785de
update
guillaume-chervet Dec 20, 2024
cb585a7
fix
guillaume-chervet Dec 20, 2024
41ea8db
update
guillaume-chervet Dec 20, 2024
b4b88d2
Update
guillaume-chervet Dec 20, 2024
437edbf
sssss
guillaume-chervet Dec 20, 2024
e3e7cdf
Continue
guillaume-chervet Dec 21, 2024
aabe661
youhou
guillaume-chervet Dec 27, 2024
9f06062
clean
guillaume-chervet Dec 27, 2024
1cad2fc
Merge branch 'main' into feature/retry-with-deadletter-queue
guillaume-chervet Dec 28, 2024
491e5ad
clean
guillaume-chervet Dec 28, 2024
9bff0fa
Merge branch 'feature/retry-with-deadletter-queue' of https://github.…
guillaume-chervet Dec 28, 2024
2f9ae96
clean :)
guillaume-chervet Dec 28, 2024
717f197
test
guillaume-chervet Dec 30, 2024
b5a2700
test
guillaume-chervet Dec 30, 2024
6edf95f
test
guillaume-chervet Dec 30, 2024
b3202ed
update
guillaume-chervet Dec 30, 2024
83ab0b0
last fix
guillaume-chervet Dec 30, 2024
a9492fb
clen
guillaume-chervet Dec 30, 2024
b0a8781
update
guillaume-chervet Dec 30, 2024
cbb102d
upgrade libraies
guillaume-chervet Dec 30, 2024
4943cfd
clean
guillaume-chervet Dec 30, 2024
04b47f7
u^date
guillaume-chervet Dec 30, 2024
5b4c501
dddd
guillaume-chervet Dec 30, 2024
2c33dd1
fix
guillaume-chervet Dec 31, 2024
06f3750
clean
guillaume-chervet Dec 31, 2024
cbc27fe
fix
guillaume-chervet Dec 31, 2024
69a2b7b
update
guillaume-chervet Dec 31, 2024
2668d2f
test
guillaume-chervet Dec 31, 2024
e28a152
test
guillaume-chervet Dec 31, 2024
9bb5228
test
guillaume-chervet Dec 31, 2024
a72b51d
update
guillaume-chervet Dec 31, 2024
b0f76a2
last clean
guillaume-chervet Dec 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

Why use SlimFaas?
- Scale to 0 after a period of inactivity (work with deployment and statefulset)
- Scale up : compatible with HPA (Horizontal Auto Scaler) and Keda
- Synchronous HTTP calls
- Asynchronous HTTP calls
- Allows you to limit the number of parallel HTTP requests for each underlying function
- Retry: 3 times with graduation: 2 seconds, 4 seconds, 8 seconds
- Retry Pattern Configurable: 3 times with graduation: 2 seconds, 4 seconds, 8 seconds
- Private and Public functions
- Private functions can be accessed only by internal namespace http call from pods
- Synchronous Publish/Subscribe internal events via HTTP calls to every replicas via HTTP without any use of specific drivers/libraries (**Couple you application with SlimFaas**)
- Synchronous Publish/Subscribe internal events via HTTP calls to every replicas via HTTP without any use of specific drivers/libraries (**Couple your application with SlimFaas**)
- Mind Changer: REST API that show the status of your functions and allow to wake up your infrastructure (**Couple your application with Slimfaas**)
- Very useful to inform end users that your infrastructure is starting
- Plug and Play: just deploy a standard pod
Expand All @@ -27,7 +28,8 @@ To test SlimFaas on your local machine by using kubernetes with Docker Desktop,

```bash
git clone https://github.com/AxaFrance/slimfaas.git
cd slimfaas/demo
cd slimfaas
cd demo
# Create slimfaas service account and pods
kubectl apply -f deployment-slimfaas.yml
# Expose SlimFaaS service as NodePort or Ingress
Expand All @@ -41,6 +43,7 @@ kubectl apply -f deployment-functions.yml
kubectl apply -f deployment-mysql.yml
# to run Single Page webapp demo (optional) on http://localhost:8000
docker run -p 8000:8000 --rm axaguildev/fibonacci-webapp:latest
kubectl port-forward svc/slimfaas-nodeport 30021:5000 -n slimfaas-demo
```

Now, you can access your pod via SlimFaas proxy:
Expand Down Expand Up @@ -165,6 +168,8 @@ spec:
SlimFaas/SubscribeEvents: "Public:my-event-name1,Private:my-event-name2,my-event-name3" # comma separated list of event names
SlimFaas/DefaultVisibility: "Public" # Public or Private (private can be accessed only by internal namespace https call from pods)
SlimFaas/UrlsPathStartWithVisibility: "Private:/mypath/subPath,Private:/mysecondpath" # Public or Private (private can be accessed only by internal namespace https call from pods)
SlimFaas/SynchrounousRetry: "2;4;8"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to delete

SlimFaas/AsynchrounousRetry: "2;4;8"
spec:
serviceAccountName: default
containers:
Expand Down Expand Up @@ -372,6 +377,28 @@ spec:
- **SlimFaas/ExcludeDeploymentsFromVisibilityPrivate** : ""
- Comma separated list of deployment names or statefulset names
- Message from that pods will be considered as public. It is useful if you want to exclude some pods from the private visibility, for example for a backend for frontend.
- **SlimFaas/Configuration** : json configuration
- Allows you to define a configuration for your functions. For example, you can define a timeout for HTTP calls, a retry pattern for timeouts and HTTP status codes.

````bash
{
"DefaultSync":{
"HttpTimeout": 30, # Timeout in seconds
"TimeoutRetries": [2,4,8] # Retry pattern in seconds
"HttpStatusRetries": [500,502,503] # Retry only for 500,502,503 HTTP status codes
}
"DefaultAsync":{
"HttpTimeout": 30, # Timeout in seconds
"TimeoutRetries": [2,4,8] # Retry pattern in seconds
"HttpStatusRetries": [500,502,503] # Retry only for 500,502,503 HTTP status codes
},
"DefaultPublish":{
"HttpTimeout": 30, # Timeout in seconds
"TimeoutRetries": [2,4,8] # Retry pattern in seconds
"HttpStatusRetries": [500,502,503] # Retry only for 500,502,503 HTTP status codes
}
}
````
- **SlimFaas/Schedule** : json configuration
- Allows you to define a schedule for your functions. If you want to wake up your infrastructure at 07:00 or for example scale down after 60 seconds of inactivity after 07:00 and scale down after 10 seconds of inactivity after 21:00. Time zones are defined as IANA time zones. The full list is available [here](https://nodatime.org/TimeZones)

Expand All @@ -380,10 +407,10 @@ spec:
{
"TimeZoneID":"Europe/Paris", # Time Zone ID can be found here: https://nodatime.org/TimeZones
"Default":{
"WakeUp":["07:00"], // Wake up your infrastructure at 07:00
"WakeUp":["07:00"], # Wake up your infrastructure at 07:00
"ScaleDownTimeout":[
{"Time":"07:00","Value":20}, // Scale down after 20 seconds of inactivity after 07:00
{"Time":"21:00","Value":10} // Scale down after 10 seconds of inactivity after 21:00
{"Time":"07:00","Value":20}, # Scale down after 20 seconds of inactivity after 07:00
{"Time":"21:00","Value":10} # Scale down after 10 seconds of inactivity after 21:00
]
}
}
Expand Down
46 changes: 42 additions & 4 deletions demo/deployment-functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,28 @@ spec:
automountServiceAccountToken: false
containers:
- name: fibonacci1
image: axaguildev/fibonacci:0.24.18
image: axaguildev/fibonacci:pr-77-815
livenessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 3
periodSeconds: 1
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
env:
- name: ASPNETCORE_URLS
value: http://+:5000
- name: Logging__LogLevel__Default
value: Debug
resources:
limits:
memory: "96Mi"
Expand Down Expand Up @@ -65,14 +76,23 @@ spec:
automountServiceAccountToken: false
containers:
- name: fibonacci2
image: axaguildev/fibonacci:0.24.18
image: axaguildev/fibonacci:77-839
livenessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 3
periodSeconds: 1
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
env:
- name: ASPNETCORE_URLS
value: http://+:5000
Expand Down Expand Up @@ -109,14 +129,23 @@ spec:
automountServiceAccountToken: false
containers:
- name: fibonacci3
image: axaguildev/fibonacci:0.24.18
image: axaguildev/fibonacci:pr-77-815
livenessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 3
periodSeconds: 1
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
env:
- name: ASPNETCORE_URLS
value: http://+:5000
Expand Down Expand Up @@ -158,14 +187,23 @@ spec:
automountServiceAccountToken: false
containers:
- name: fibonacci4
image: axaguildev/fibonacci:0.24.18
image: axaguildev/fibonacci:pr-77-815
livenessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /health
port: 5000
initialDelaySeconds: 3
periodSeconds: 1
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
env:
- name: ASPNETCORE_URLS
value: http://+:5000
Expand Down
30 changes: 29 additions & 1 deletion demo/deployment-slimfaas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ roleRef:
name: deployment-statefulset-manager
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: endpoints-viewer
namespace: slimfaas-demo
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: slimfaas-endpoints-viewer
namespace: slimfaas-demo
subjects:
- kind: ServiceAccount
name: slimfaas
namespace: slimfaas-demo
roleRef:
kind: Role
name: endpoints-viewer
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand All @@ -84,7 +109,7 @@ spec:
serviceAccountName: slimfaas
containers:
- name: slimfaas
image: axaguildev/slimfaas:0.24.18
image: axaguildev/slimfaas:pr-77-834
livenessProbe:
httpGet:
path: /health
Expand Down Expand Up @@ -114,6 +139,9 @@ spec:
value: "Debug"
#- name: SLIMDATA_CONFIGURATION
# value: |
# {"coldStart":"true"}
#- name: SLIMDATA_CONFIGURATION
# value: |
# {"lowerElectionTimeout":"500","upperElectionTimeout":"1000","requestTimeout":"00:01:20.0000000","rpcTimeout":"00:00:40.0000000","heartbeatThreshold":"0.5"}
#- name: SLIMDATA_SOCKETS_HTTP_HANDLER_TIMEOUT
# value: "500"
Expand Down
8 changes: 7 additions & 1 deletion src/Fibonacci/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@

app.MapGet("/health", () => "OK");

app.MapGet("/error", async () =>
{
await Task.Delay(100);
throw new Exception("Error");
});

app.MapGet("/hello/{name}", ([FromServices] ILogger<Fibonacci> logger, string name) =>
{
logger.LogInformation("Hello Called with name: {Name}", name);
Expand All @@ -46,7 +52,7 @@
[FromServices] Fibonacci fibonacci,
FibonacciInput input) =>
{
logger.LogInformation("Fibonacci Called");
logger.LogInformation("Fibonacci Called with input: {Input}", input.Input);
var output = new FibonacciOutput();
output.Result = fibonacci.Run(input.Input);
logger.LogInformation("Fibonacci output: {Output}", output.Result);
Expand Down
2 changes: 1 addition & 1 deletion src/SlimData/Commands/AddKeyValueCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct AddKeyValueCommand : ISerializable<AddKeyValueCommand>
public string Key { get; set; }
public ReadOnlyMemory<byte> Value { get; set; }

long? IDataTransferObject.Length => sizeof(int) + Value.Length;
long? IDataTransferObject.Length => Encoding.UTF8.GetByteCount(Key) + Value.Length;

public async ValueTask WriteToAsync<TWriter>(TWriter writer, CancellationToken token)
where TWriter : notnull, IAsyncBinaryWriter
Expand Down
45 changes: 45 additions & 0 deletions src/SlimData/Commands/ListCallbackCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Text;
using DotNext.IO;
using DotNext.Runtime.Serialization;
using DotNext.Text;

namespace SlimData.Commands;

public struct ListCallbackCommand : ISerializable<ListCallbackCommand>
{
public const int Id = 15;

public string Identifier { get; set; }
public string Key { get; set; }

public int HttpCode { get; set; }

public long NowTicks { get; set; }

public async ValueTask WriteToAsync<TWriter>(TWriter writer, CancellationToken token) where TWriter : notnull, IAsyncBinaryWriter
{
var command = this;
await writer.EncodeAsync(command.Identifier.AsMemory(), new EncodingContext(Encoding.UTF8, false),
LengthFormat.LittleEndian, token).ConfigureAwait(false);
await writer.EncodeAsync(command.Key.AsMemory(), new EncodingContext(Encoding.UTF8, false),
LengthFormat.LittleEndian, token).ConfigureAwait(false);
await writer.WriteLittleEndianAsync(HttpCode, token).ConfigureAwait(false);
await writer.WriteLittleEndianAsync(NowTicks, token).ConfigureAwait(false);
}

long? IDataTransferObject.Length => Encoding.UTF8.GetByteCount(Identifier) + sizeof(int) + Encoding.UTF8.GetByteCount(Key) + sizeof(long);

public static async ValueTask<ListCallbackCommand> ReadFromAsync<TReader>(TReader reader, CancellationToken token) where TReader : notnull, IAsyncBinaryReader
{
var identifier = await reader.DecodeAsync( new DecodingContext(Encoding.UTF8, false), LengthFormat.LittleEndian, token: token).ConfigureAwait(false);
var key = await reader.DecodeAsync( new DecodingContext(Encoding.UTF8, false), LengthFormat.LittleEndian, token: token).ConfigureAwait(false);

return new ListCallbackCommand
{
Identifier = identifier.ToString(),
Key = key.ToString(),
HttpCode = await reader.ReadLittleEndianAsync<Int32>(token).ConfigureAwait(false),
NowTicks = await reader.ReadLittleEndianAsync<Int64>(token).ConfigureAwait(false)
};
}
}
50 changes: 48 additions & 2 deletions src/SlimData/Commands/ListLeftPushCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,42 @@ public struct ListLeftPushCommand : ISerializable<ListLeftPushCommand>
public const int Id = 13;

public string Key { get; set; }

public string Identifier { get; set; }
public long NowTicks { get; set; }

public int RetryTimeout { get; set; }

public List<int> Retries { get; set; }

public List<int> HttpStatusCodesWorthRetrying { get; set; }

public ReadOnlyMemory<byte> Value { get; set; }

long? IDataTransferObject.Length => sizeof(int) + Value.Length;
long? IDataTransferObject.Length => Encoding.UTF8.GetByteCount(Key) + Value.Length + Encoding.UTF8.GetByteCount(Identifier) + sizeof(long) + sizeof(int) + Retries.Count * sizeof(int) + sizeof(int) + sizeof(int) + HttpStatusCodesWorthRetrying.Count * sizeof(int);

public async ValueTask WriteToAsync<TWriter>(TWriter writer, CancellationToken token)
where TWriter : notnull, IAsyncBinaryWriter
{
var command = this;
await writer.EncodeAsync(command.Key.AsMemory(), new EncodingContext(Encoding.UTF8, false),
LengthFormat.LittleEndian, token).ConfigureAwait(false);
await writer.EncodeAsync(command.Identifier.AsMemory(), new EncodingContext(Encoding.UTF8, false),
LengthFormat.LittleEndian, token).ConfigureAwait(false);
await writer.WriteLittleEndianAsync(NowTicks, token).ConfigureAwait(false);
await writer.WriteLittleEndianAsync(RetryTimeout, token).ConfigureAwait(false);
await writer.WriteAsync(command.Value, LengthFormat.Compressed, token).ConfigureAwait(false);
await writer.WriteLittleEndianAsync(Retries.Count, token).ConfigureAwait(false);
foreach (var retry in Retries)
{
await writer.WriteLittleEndianAsync(retry, token).ConfigureAwait(false);
}
await writer.WriteLittleEndianAsync(HttpStatusCodesWorthRetrying.Count, token).ConfigureAwait(false);
foreach (var httpStatus in HttpStatusCodesWorthRetrying)
{
await writer.WriteLittleEndianAsync(httpStatus, token).ConfigureAwait(false);
}

}

#pragma warning disable CA2252
Expand All @@ -29,11 +54,32 @@ public static async ValueTask<ListLeftPushCommand> ReadFromAsync<TReader>(TReade
where TReader : notnull, IAsyncBinaryReader
{
var key = await reader.DecodeAsync(new DecodingContext(Encoding.UTF8, false), LengthFormat.LittleEndian, token: token).ConfigureAwait(false);
var identifier = await reader.DecodeAsync(new DecodingContext(Encoding.UTF8, false), LengthFormat.LittleEndian, token: token).ConfigureAwait(false);
var nowTicks = await reader.ReadLittleEndianAsync<Int64>(token).ConfigureAwait(false);
var timeout = await reader.ReadLittleEndianAsync<Int32>(token).ConfigureAwait(false);
using var value = await reader.ReadAsync(LengthFormat.Compressed, token: token).ConfigureAwait(false);
var retriesCount = await reader.ReadLittleEndianAsync<Int32>(token).ConfigureAwait(false);
var retries = new List<int>(retriesCount);
while (retriesCount-- > 0)
{
retries.Add(await reader.ReadLittleEndianAsync<Int32>(token).ConfigureAwait(false));
}
var httpStatusCodesWorthRetryingCount = await reader.ReadLittleEndianAsync<Int32>(token).ConfigureAwait(false);
var httpStatusCodesWorthRetrying = new List<int>(httpStatusCodesWorthRetryingCount);
while (httpStatusCodesWorthRetryingCount-- > 0)
{
httpStatusCodesWorthRetrying.Add(await reader.ReadLittleEndianAsync<Int32>(token).ConfigureAwait(false));
}

return new ListLeftPushCommand
{
Key = key.ToString(),
Value = value.Memory.ToArray()
Identifier = identifier.ToString(),
NowTicks = nowTicks,
RetryTimeout = timeout,
Retries = retries,
Value = value.Memory.ToArray(),
HttpStatusCodesWorthRetrying = httpStatusCodesWorthRetrying
};
}
}
Loading
Loading