Skip to content

Commit

Permalink
fix(serverless): retrieve environment variables when booting (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz committed Jun 4, 2023
1 parent 6979a7c commit cacb962
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-trees-march.md
@@ -0,0 +1,5 @@
---
'@lagon/serverless': patch
---

Retrieve environment variables when booting
24 changes: 22 additions & 2 deletions crates/serverless/src/deployments/mod.rs
Expand Up @@ -74,6 +74,8 @@ type QueryResult = (
usize,
Option<String>,
Option<String>,
Option<String>,
Option<String>,
);

pub async fn get_deployments<D>(mut conn: PooledConn, downloader: Arc<D>) -> Result<Deployments>
Expand All @@ -96,13 +98,17 @@ SELECT
Function.tickTimeout,
Function.totalTimeout,
Function.cron,
Domain.domain
Domain.domain,
EnvVariable.key,
EnvVariable.value
FROM
Deployment
INNER JOIN Function
ON Deployment.functionId = Function.id
LEFT JOIN Domain
ON Function.id = Domain.functionId
LEFT JOIN EnvVariable
ON Function.id = EnvVariable.functionId
WHERE
Function.cron IS NULL
OR
Expand All @@ -121,6 +127,8 @@ OR
total_timeout,
cron,
domain,
env_key,
env_value,
): QueryResult| {
let assets = serde_json::from_str::<AssetObj>(&assets)
.map(|asset_obj| asset_obj.0)
Expand All @@ -134,6 +142,12 @@ OR
}

deployment.assets.extend(assets.clone());

if let Some(env_key) = env_key.clone() {
deployment
.environment_variables
.insert(env_key, env_value.clone().unwrap_or_default());
}
})
.or_insert(Deployment {
id,
Expand All @@ -147,7 +161,13 @@ OR
})
.unwrap_or_default(),
assets: HashSet::from_iter(assets.iter().cloned()),
environment_variables: HashMap::new(),
environment_variables: env_key
.map(|key| {
let mut environment_variables = HashMap::new();
environment_variables.insert(key, env_value.unwrap_or_default());
environment_variables
})
.unwrap_or_default(),
memory,
tick_timeout,
total_timeout,
Expand Down

0 comments on commit cacb962

Please sign in to comment.