Skip to content

Commit 515fe2b

Browse files
authored
Merge pull request #10 from zhanghaomiao/feat/config
refactor: Migrate workflow timeline from Google Charts to ECharts and…
2 parents 7ec653e + 0a365d2 commit 515fe2b

22 files changed

Lines changed: 643 additions & 1430 deletions

File tree

app/api/endpoints/workflows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ async def get_workflow_log(
165165
return await service.get_workflow_log(workflow_id)
166166

167167

168-
@router.get("/{workflow_id}/configfiles", response_model=dict[str, str])
168+
@router.get("/{workflow_id}/configfiles", response_model=list[PathContent])
169169
async def get_configfiles(
170170
workflow_id: uuid.UUID,
171171
db: AsyncSession = Depends(get_async_session),

app/core/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def get_env_files() -> list[str]:
88
"""Safely get environment files, avoiding permission errors in containers."""
9-
files = [".env"]
9+
files = []
1010
try:
1111
# Check for user-level config
1212
home_cfg = Path.home() / ".config/flowo/.env"
@@ -16,6 +16,7 @@ def get_env_files() -> list[str]:
1616
except (PermissionError, RuntimeError):
1717
# Fallback if home directory is restricted
1818
pass
19+
files.append(".env")
1920
return files
2021

2122

app/plugin/client/log_handler.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ def emit(self, record: LogRecord) -> None:
132132
schema_data = parser_func(record)
133133

134134
# 2. Send to API
135-
self._send_to_api(event_name, schema_data.model_dump(mode="json"))
135+
data = schema_data.model_dump(mode="json")
136+
137+
if event_name == "workflow_started":
138+
self.context["configfiles"] = self._get_configfiles()
139+
140+
self._send_to_api(event_name, data)
136141
except Exception as e:
137142
logger.debug(f"Failed to process event {event_name}: {e}")
138143

@@ -189,9 +194,27 @@ def flowo_path_valid(self):
189194
)
190195
return
191196

197+
def _get_configfiles(self) -> list[str]:
198+
"""Extract configfiles from global snakemake workflow object."""
199+
try:
200+
import snakemake.workflow
201+
202+
if (
203+
hasattr(snakemake.workflow, "workflow")
204+
and snakemake.workflow.workflow
205+
and hasattr(snakemake.workflow.workflow, "configfiles")
206+
):
207+
return [str(f) for f in snakemake.workflow.workflow.configfiles]
208+
except Exception as e:
209+
logger.debug(f"Failed to access snakemake workflow configfiles: {e}")
210+
return []
211+
192212
def close(self) -> None:
193213
self.file_handler.close()
194214

215+
if self._client.is_closed:
216+
return
217+
195218
workflow_id = self.context.get("current_workflow_id")
196219
if workflow_id and settings.FLOWO_USER_TOKEN:
197220
url = (

app/plugin/server/handlers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def handle(
4242
dryrun=context.get("dryrun", False),
4343
status=Status.RUNNING,
4444
started_at=datetime.now(),
45-
# maybe we need to get configfiles later
46-
# configfiles=context.get("configfiles"),
45+
configfiles=context.get("configfiles"),
4746
)
4847
session.add(workflow)
4948
context["current_workflow_id"] = data.workflow_id

app/services/workflow.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,18 @@ async def get_configfiles(self, workflow_id: uuid.UUID):
186186
status_code=404, detail="configfiles or workflow not found"
187187
)
188188

189-
data = {}
189+
data = []
190190
for configfile in workflow.configfiles:
191191
try:
192-
configfile_path = str(configfile).replace(
193-
workflow.flowo_working_path, "/work_dir/"
194-
)
195-
with open(configfile_path) as f:
196-
data[configfile] = f.read()
192+
content = get_file_content(configfile)
193+
content.path = configfile
194+
data.append(content)
197195
except Exception as e:
198-
data[configfile] = f"Failed to open file: {str(e)}"
196+
data.append(
197+
PathContent(
198+
path=configfile, content=f"Error reading file: {str(e)}"
199+
)
200+
)
199201

200202
return data
201203

docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ services:
7575
- caddy_data_dev:/data
7676
- caddy_config_dev:/config
7777
ports:
78-
- "${PORT:-3101}:80"
78+
- "${PORT:-3100}:80"
7979
depends_on:
8080
- flowo-backend
8181
- flowo-frontend

0 commit comments

Comments
 (0)