Skip to content

Commit 0d2d719

Browse files
authored
Merge pull request #75 from OneLiteFeatherNET/refactor/server
Refactor/server
2 parents 37d7db6 + 2a1734d commit 0d2d719

File tree

19 files changed

+212
-31
lines changed

19 files changed

+212
-31
lines changed

Cargo.lock

Lines changed: 80 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "feedback-fusion"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
license = "MIT"
66

@@ -22,6 +22,7 @@ getset = "0.1.2"
2222
itertools = "0.12.1"
2323
kanal = "0.1.0-pre8"
2424
lazy_static = "1.4.0"
25+
log = "0.4.22"
2526
nanoid = "0.4.0"
2627
notify = { version = "6.1.1", default-features = false, features = [
2728
"macos_kqueue",
@@ -45,6 +46,7 @@ tonic-reflection = "0.11.0"
4546
tonic-web = "0.11.0"
4647
tokio = { version = "1.37.0", features = ["full"] }
4748
tower = "0.4.13"
49+
tokio-retry = "0.3"
4850
tower-http = { version = "=0.4.4", features = ["trace", "validate-request"] }
4951
tracing = "0.1.39"
5052
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

Makefile.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ dependencies = ["docker_network"]
7070
script = "docker compose -f tests/_common/oidc-mock/docker-compose.yaml up -d && sleep 5 && curl -s -o /dev/null http://localhost:5151/.well-known/openid-configuration"
7171

7272
[tasks.integration_test]
73-
env = { OIDC_DISCOVERY_URL = "http://localhost:5151", OIDC_CLIENT_ID = "client", OIDC_CLIENT_SECRET = "secret", RUST_LOG = "INFO" }
73+
env = { OIDC_PROVIDER = "http://localhost:5151", OIDC_CLIENT_ID = "client", OIDC_CLIENT_SECRET = "secret", RUST_LOG = "INFO" }
7474
command = "cargo"
7575
args = ["test", "--no-fail-fast", "--test", "integration_test"]
7676

@@ -86,7 +86,7 @@ docker run --name feedback-fusion -d \
8686
-e POSTGRES_PASSWORD=password \
8787
-e POSTGRES_DATABASE=postgres \
8888
-e POSTGRES_ENDPOINT=postgres:5432 \
89-
-e OIDC_DISCOVERY_URL=http://oidc-server-mock \
89+
-e OIDC_PROVIDER=http://oidc-server-mock \
9090
-e OIDC_ISSUER=http://localhost:5151 \
9191
-e RUST_LOG=DEBUG \
9292
--network feedback-fusion -p 8000:8000 feedback-fusion
@@ -125,7 +125,7 @@ docker run --name feedback-fusion -d \
125125
-e MYSQL_PASSWORD=password \
126126
-e MYSQL_DATABASE=database \
127127
-e MYSQL_ENDPOINT=mysql:3306 \
128-
-e OIDC_DISCOVERY_URL=http://oidc-server-mock \
128+
-e OIDC_PROVIDER=http://oidc-server-mock \
129129
-e OIDC_ISSUER=http://localhost:5151 \
130130
-e RUST_LOG=DEBUG \
131131
--network feedback-fusion -p 8000:8000 feedback-fusion
@@ -183,7 +183,7 @@ docker run --name feedback-fusion -d \
183183
-e MSSQL_PASSWORD=Password1 \
184184
-e MSSQL_DATABASE=master \
185185
-e MSSQL_ENDPOINT=mssql:1433 \
186-
-e OIDC_DISCOVERY_URL=http://oidc-server-mock \
186+
-e OIDC_PROVIDER=http://oidc-server-mock \
187187
-e OIDC_ISSUER=http://localhost:5151 \
188188
-e RUST_LOG=DEBUG \
189189
--network feedback-fusion -p 8000:8000 feedback-fusion

charts/feedback-fusion/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.1.3
18+
version: 0.1.4
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.1.1"
24+
appVersion: "0.1.2"

charts/feedback-fusion/templates/configmap-preset.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ kind: ConfigMap
44
metadata:
55
name: {{ .Values.feedbackFusion.preset.name }}
66
data:
7-
{{- if .Values.feedbackFusion.preset.data }}
7+
{{- with .Values.feedbackFusion.preset.data }}
88
config.yaml: |
9-
{{ .Values.feedbackFusion.preset.data | indent 4 }}
9+
{{ toYaml . | nindent 4 }}
1010
{{- end }}
1111
{{- end }}

charts/feedback-fusion/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ spec:
4848
{{- end }}
4949
livenessProbe:
5050
{{- toYaml .Values.livenessProbe | nindent 12 }}
51-
readinessProbe:
52-
{{- toYaml .Values.readinessProbe | nindent 12 }}
51+
startupProbe:
52+
{{- toYaml .Values.startupProbe | nindent 12 }}
5353
resources:
5454
{{- toYaml .Values.resources | nindent 12 }}
5555
volumeMounts:

charts/feedback-fusion/values.yaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ resources: {}
6565
livenessProbe:
6666
grpc:
6767
port: 8000
68-
readinessProbe:
68+
periodSeconds: 5
69+
startupProbe:
6970
grpc:
7071
port: 8000
72+
periodSeconds: 2
73+
failureThreshold: 10
7174

7275
# Additional volumes on the output Deployment definition.
7376
volumes: []
@@ -93,14 +96,32 @@ feedbackFusion:
9396
enabled: false
9497
name: feedback-fusion-preset
9598
create: false
96-
data: |
99+
data:
100+
# targets:
101+
# - id: target
102+
# name: TestTarget
103+
# description: A nice Target
104+
# prompts:
105+
# - id: prompt
106+
# title: Testprompt
107+
# description: A nice Prompt
108+
# active: true
109+
# fields:
110+
# - id: field1
111+
# title: TextField
112+
# field_type: text
113+
# options:
114+
# type: text
115+
# lines: 1
116+
# placeholder: test
117+
97118

98119
config:
99120
secret: feedback-fusion-config
100121
# RUST_LOG: INFO
101122
# GLOBAL_RATE_LIMIT: 10
102123
# OIDC_AUDIENCE: ""
103-
# OIDC_DISCOVERY_URL: ""
124+
# OIDC_PROVIDER: ""
104125
#
105126
# POSTGRES_ENDPOINT: ""
106127
# POSTGRES_USERNAME: ""

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ lazy_static! {
3939
pub struct Config {
4040
#[serde(default = "default_global_rate_limit")]
4141
global_rate_limit: u64,
42-
oidc_discovery_url: String,
42+
oidc_provider: String,
4343
#[serde(default = "default_oidc_audience")]
4444
oidc_audience: String,
4545
oidc_issuer: Option<String>,

src/database/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
use crate::{database::migration::Migration, prelude::*};
2525
use rbatis::RBatis;
26+
use tokio_retry::{
27+
strategy::{jitter, FibonacciBackoff},
28+
Retry,
29+
};
2630

2731
pub mod migration;
2832
pub mod schema;
@@ -105,7 +109,25 @@ macro_rules! database_configuration {
105109
#[cfg(feature = $scheme)]
106110
Self::$ident(config) => {
107111
let url = config.to_url($scheme);
108-
connection.init($driver {}, url.as_str())?;
112+
113+
let retry_strategy = FibonacciBackoff::from_millis(500)
114+
.map(jitter)
115+
.take(5);
116+
117+
Retry::spawn(retry_strategy.clone(), || async {
118+
match connection.init($driver {}, url.as_str()) {
119+
Ok(result) => Ok(result),
120+
Err(error) => {
121+
error!("Failed to establish DatabaseConnection, retrying in {}s", retry_strategy.clone().next().unwrap().as_secs());
122+
error!("{}", error);
123+
124+
Err(error)
125+
}
126+
}
127+
}).await?;
128+
129+
connection.intercepts.clear();
130+
connection.intercepts.push(std::sync::Arc::new(rbatis::plugin::intercept_log::LogInterceptor::new(log::LevelFilter::Debug)));
109131

110132
// perform migrations
111133
let last: Option<Migration> = Migration::select_latest(&connection).await.unwrap_or_default();

0 commit comments

Comments
 (0)