fix: language field broke flow too

This commit is contained in:
Ruben Fiszel
2022-05-18 23:28:02 +02:00
parent 133fe388d4
commit c039ffe81e
4 changed files with 24 additions and 7 deletions

View File

@@ -0,0 +1 @@
-- Add down migration script here

View File

@@ -0,0 +1,6 @@
-- Add up migration script here
ALTER TABLE queue
ALTER COLUMN language DROP NOT NULL;
ALTER TABLE completed_job
ALTER COLUMN language DROP NOT NULL;

View File

@@ -84,7 +84,7 @@ pub struct QueuedJob {
pub flow_status: Option<serde_json::Value>,
pub raw_flow: Option<serde_json::Value>,
pub is_flow_step: bool,
pub language: ScriptLang,
pub language: Option<ScriptLang>,
}
#[derive(Debug, sqlx::FromRow, Serialize)]
@@ -113,7 +113,7 @@ struct CompletedJob {
flow_status: Option<serde_json::Value>,
raw_flow: Option<serde_json::Value>,
is_flow_step: bool,
language: ScriptLang,
language: Option<ScriptLang>,
}
#[derive(Deserialize, Clone, Copy)]
@@ -864,7 +864,7 @@ struct UnifiedJob {
permissioned_as: String,
flow_status: Option<serde_json::Value>,
is_flow_step: bool,
language: ScriptLang,
language: Option<ScriptLang>,
}
impl From<UnifiedJob> for Job {

View File

@@ -347,14 +347,19 @@ async fn handle_job(
let (inner_content, requirements_o, language) = if matches!(job.job_kind, JobKind::Preview)
{
let code = (job.raw_code.as_ref().unwrap_or(&"no raw code".to_owned())).to_owned();
let reqs = if job.language == ScriptLang::Python3 {
let reqs = if job
.language
.as_ref()
.map(|x| matches!(x, ScriptLang::Python3))
.unwrap_or(false)
{
Some(parser::parse_python_imports(&code)?.join("\n"))
} else {
None
};
(code, reqs, job.language.to_owned())
} else {
sqlx::query_as::<_, (String, Option<String>, ScriptLang)>("SELECT content, lock, language FROM script WHERE hash = $1 AND (workspace_id = $2 OR workspace_id = 'starter')")
sqlx::query_as::<_, (String, Option<String>, Option<ScriptLang>)>("SELECT content, lock, language FROM script WHERE hash = $1 AND (workspace_id = $2 OR workspace_id = 'starter')")
.bind(&job.script_hash.unwrap_or(ScriptHash(0)).0)
.bind(&job.workspace_id)
.fetch_optional(db)
@@ -363,7 +368,12 @@ async fn handle_job(
};
match language {
ScriptLang::Python3 => {
None => {
return Err(Error::ExecutionErr(
"Require language to be not null".to_string(),
))?;
}
Some(ScriptLang::Python3) => {
let requirements = requirements_o
.ok_or_else(|| Error::InternalErr(format!("lockfile missing")))?;
@@ -494,7 +504,7 @@ print(res_json)
status = handle_child(job, db, &mut logs, &mut last_line, timeout, child).await;
}
}
ScriptLang::Deno => {
Some(ScriptLang::Deno) => {
logs.push_str("\n\n--- DENO CODE EXECUTION ---\n");
set_logs(logs, job.id, db).await;