mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-09 08:03:50 +00:00
fix same_worker/shared to work with and without nsjail
This commit is contained in:
@@ -542,28 +542,27 @@ pub async fn run_worker(
|
||||
.expect("could not create job dir");
|
||||
|
||||
let same_worker = job.same_worker;
|
||||
let is_flow = job.job_kind == JobKind::Flow || job.job_kind == JobKind::FlowPreview || job.job_kind == JobKind::FlowDependencies;
|
||||
|
||||
if is_flow && same_worker {
|
||||
let target = &format!("{job_dir}/shared");
|
||||
if let Some(parent_flow) = job.parent_job {
|
||||
let parent_shared_dir = format!("{worker_dir}/{parent_flow}/shared");
|
||||
if metadata(&parent_shared_dir).await.is_err() {
|
||||
DirBuilder::new()
|
||||
.recursive(true)
|
||||
.create(&parent_shared_dir)
|
||||
.await
|
||||
.expect("could not create parent shared dir");
|
||||
}
|
||||
symlink(&parent_shared_dir, target)
|
||||
.await
|
||||
.expect("could not symlink target");
|
||||
} else {
|
||||
let target = &format!("{job_dir}/shared");
|
||||
|
||||
if same_worker && job.parent_job.is_some() {
|
||||
let parent_flow = job.parent_job.unwrap();
|
||||
let parent_shared_dir = format!("{worker_dir}/{parent_flow}/shared");
|
||||
if metadata(&parent_shared_dir).await.is_err() {
|
||||
DirBuilder::new()
|
||||
.create(target)
|
||||
.recursive(true)
|
||||
.create(&parent_shared_dir)
|
||||
.await
|
||||
.expect("could not create shared dir");
|
||||
.expect("could not create parent shared dir");
|
||||
}
|
||||
symlink(&parent_shared_dir, target)
|
||||
.await
|
||||
.expect("could not symlink target");
|
||||
} else {
|
||||
DirBuilder::new()
|
||||
.create(target)
|
||||
.await
|
||||
.expect("could not create shared dir");
|
||||
}
|
||||
let tx = db.begin().await.expect("could not start token transaction");
|
||||
let (tx, token) = create_token_for_owner(
|
||||
@@ -577,6 +576,7 @@ pub async fn run_worker(
|
||||
.await.expect("could not create job token");
|
||||
tx.commit().await.expect("could not commit job token");
|
||||
let job_client = windmill_api_client::create_client(&worker_config.base_url, token.clone());
|
||||
let is_flow = job.job_kind == JobKind::Flow || job.job_kind == JobKind::FlowPreview || job.job_kind == JobKind::FlowDependencies;
|
||||
|
||||
if let Some(err) = handle_queued_job(
|
||||
job.clone(),
|
||||
@@ -611,6 +611,7 @@ pub async fn run_worker(
|
||||
.await;
|
||||
};
|
||||
|
||||
|
||||
if !worker_config.keep_job_dir && !(is_flow && same_worker) {
|
||||
let _ = tokio::fs::remove_dir_all(job_dir).await;
|
||||
}
|
||||
@@ -1016,26 +1017,15 @@ async fn handle_code_execution_job(
|
||||
format!(
|
||||
r#"
|
||||
mount {{
|
||||
src: "{worker_dir}/{}/shared"
|
||||
src: "{job_dir}/shared"
|
||||
dst: "/tmp/shared"
|
||||
is_bind: true
|
||||
rw: true
|
||||
}}
|
||||
"#,
|
||||
job.parent_job.ok_or(Error::ExecutionErr(
|
||||
"no parent job, required for same worker job".to_string()
|
||||
))?,
|
||||
"#
|
||||
)
|
||||
} else {
|
||||
r#"
|
||||
mount {
|
||||
dst: "/tmp/shared"
|
||||
fstype: "tmpfs"
|
||||
rw: true
|
||||
options: "size=500000000"
|
||||
}
|
||||
"#
|
||||
.to_string()
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
let result: error::Result<serde_json::Value> = match language {
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<Pane size={50} minSize={20} class="p-4">
|
||||
{#if $flowStore.value.same_worker}
|
||||
<div class="mb-1 bg-yellow-100 text-yellow-700 p-1 text-xs"
|
||||
>Using same_worker does not preserve /shared across individual step tests</div
|
||||
>The `./shared` folder is not passed across individual "Test this step"</div
|
||||
>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@
|
||||
<div class="p-4 h-full overflow-auto">
|
||||
<Alert type="info" title="Share a directory using same worker">
|
||||
If same worker is set, all steps will be run on the same worker and will share
|
||||
the folder `/shared` to pass data between each other.
|
||||
the folder `./shared` to pass data between each other.
|
||||
</Alert>
|
||||
<Button
|
||||
btnClasses="mt-4"
|
||||
|
||||
@@ -89,8 +89,8 @@
|
||||
title="Toggle Same Worker to have all steps be ran on the same worker"
|
||||
>
|
||||
Steps will be run one after the other on the same worker, and will share a folder at
|
||||
`/shared` in which they can store heavier data and pass them to the next step. <br
|
||||
/><br />Beware that the `/shared` folder is not preserved across suspends and sleeps.
|
||||
`./shared` in which they can store heavier data and pass them to the next step. <br
|
||||
/><br />Beware that the `./shared` folder is not preserved across suspends and sleeps.
|
||||
</Alert>
|
||||
<span class="my-2 text-sm font-bold">Same Worker</span>
|
||||
<Toggle
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { faCalendarAlt, faSliders } from '@fortawesome/free-solid-svg-icons'
|
||||
import { classNames } from '$lib/utils'
|
||||
import { Badge } from '$lib/components/common'
|
||||
import { flowStore } from '../flowStore'
|
||||
|
||||
const { select, selectedId, schedule } = getContext<FlowEditorContext>('FlowEditorContext')
|
||||
|
||||
@@ -17,20 +18,20 @@
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<div on:click={() => select('settings')} class={settingsClass}>
|
||||
<Icon data={faSliders} class="mr-2" />
|
||||
<span
|
||||
class="text-xs font-bold flex flex-row justify-between w-full gap-2 items-center flex-wrap truncate"
|
||||
>
|
||||
<span class="text-xs font-bold flex flex-row justify-between w-full gap-2 items-center truncate">
|
||||
Settings
|
||||
<span
|
||||
class={classNames('badge', $schedule?.enabled ? 'badge-on' : 'badge-off')}
|
||||
on:click|stopPropagation={() => select('settings-schedule')}
|
||||
>
|
||||
{#if $schedule?.enabled}
|
||||
<Badge color="gray"
|
||||
>{$schedule.cron}
|
||||
<Icon class={$schedule.cron ? 'ml-2' : ''} data={faCalendarAlt} scale={0.8} />
|
||||
<Badge color="gray" baseClass="truncate">
|
||||
<Icon data={faCalendarAlt} scale={0.8} />
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if $flowStore.value.same_worker}
|
||||
<Badge color="blue" baseClass="truncate">same worker</Badge>
|
||||
{/if}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user