Skip to content

Commit

Permalink
Merge pull request #124 from lucafaggianelli/dev
Browse files Browse the repository at this point in the history
Release v0.3.0
  • Loading branch information
lucafaggianelli authored Jun 6, 2023
2 parents 6864770 + c620843 commit b508884
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 76 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ pip install -r requirements-dev.txt
for development purposes, it's useful to run the example application:
```sh
cd examples/
export PYTHONPATH=$(pwd)/..
uvicorn dummy.app:app --reload --reload-dir ..

# Create a venv for the example app
python -m venv .venv
source .venv/bin/activate
pip install -r requirements

./run.sh
# or ./run.ps1 on windows
```

The React frontend is in the `frontend/` folder, enter the folder
Expand Down
3 changes: 3 additions & 0 deletions examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-e ..
python-dateutil
pandas
2 changes: 1 addition & 1 deletion examples/run.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$env:PYTHONPATH="$(pwd)/.."
$env:PYTHONPATH="$(pwd)"
python src/app.py
2 changes: 1 addition & 1 deletion examples/run.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export PYTHONPATH=$(pwd)/..
export PYTHONPATH=$(pwd)
python src/app.py
2 changes: 1 addition & 1 deletion examples/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from plombery import get_app # noqa: F401

from examples.src import sales_pipeline, sync_pipeline # noqa: F401
from src import sales_pipeline, sync_pipeline # noqa: F401


if __name__ == "__main__":
Expand Down
84 changes: 44 additions & 40 deletions frontend/src/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,61 @@ interface Props {
pipeline: Pipeline
trigger?: Trigger
run?: PipelineRun
className?: string
}

const Separator = () => <Text>/</Text>

const Breadcrumbs: React.FC<Props> = ({ pipeline, trigger, run }) => {
const Breadcrumbs: React.FC<Props> = ({
pipeline,
trigger,
run,
className,
}) => {
if (run && !trigger) {
throw new Error()
}

return (
<div className="breadcrumbs">
<Flex className="space-x-2 justify-start">
<Text>
<Link to="/">Pipelines</Link>
</Text>
<Separator />
<Text>
{trigger ? (
<Link to={`/pipelines/${pipeline.id}`}>{pipeline.name}</Link>
) : (
pipeline.name
)}
</Text>

{trigger && (
<>
<Separator />
<Text>Triggers</Text>
<Separator />
<Text>
{run ? (
<Link to={`/pipelines/${pipeline.id}/triggers/${trigger.id}`}>
{trigger.name}
</Link>
) : (
trigger.name
)}
</Text>
</>
<Flex className={`gap-x-2 justify-start flex-wrap ${className || ''}`}>
<Text>
<Link to="/">Pipelines</Link>
</Text>
<Separator />
<Text>
{trigger ? (
<Link to={`/pipelines/${pipeline.id}`}>{pipeline.name}</Link>
) : (
pipeline.name
)}
</Text>

{run && trigger && (
<>
<Separator />
<Text>Runs</Text>
<Separator />
<Text>#{run.id}</Text>
</>
)}
</Flex>
</div>
{trigger && (
<>
<Separator />
<Text>Triggers</Text>
<Separator />
<Text>
{run ? (
<Link to={`/pipelines/${pipeline.id}/triggers/${trigger.id}`}>
{trigger.name}
</Link>
) : (
trigger.name
)}
</Text>
</>
)}

{run && trigger && (
<>
<Separator />
<Text>Runs</Text>
<Separator />
<Text>#{run.id}</Text>
</>
)}
</Flex>
)
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ManualRunDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const ManualRunDialog: React.FC<Props> = ({ pipeline }) => {
icon={PlayIcon}
onClick={() => setOpen(true)}
>
Run pipeline
Run
</Button>

<Dialog
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const PageLayout: React.FC<Props> = ({ children, header }) => {
return (
<div className="bg-slate-50 p-6 sm:p-10 min-h-screen">
<Flex className="items-start">
{header && <div className="flex-grow">{header}</div>}
{header && <div className="flex-grow max-w-full">{header}</div>}
{isAuthenticated && isAuthenticationEnabled && <UserMenu />}
</Flex>

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/PipelinesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const PipelinesList: React.FC = () => {
<List>
{pipelines.map((pipeline) => (
<ListItem key={pipeline.id}>
<div>
<Text>
<div className="min-w-0">
<Text className="truncate">
<Bold>
<Link to={`/pipelines/${pipeline.id}`}>{pipeline.name}</Link>
</Bold>
Expand Down
24 changes: 14 additions & 10 deletions frontend/src/pages/pipelines/[pipelineId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,25 @@ const PipelineView: React.FC = () => {
return (
<PageLayout
header={
<Flex className="items-start">
<div>
<Flex className="justify-start space-x-2">
<Title>Pipeline {pipeline.name}</Title>
<div>
<Flex className="items-start">
<Flex className="justify-start items-start md:items-center flex-col md:flex-row min-w-0">
<Title className="truncate max-w-full">
Pipeline {pipeline.name}
</Title>
{pipeline.description && (
<Text className="truncate">
&middot; {pipeline.description}
<Text className="truncate max-w-full">
<span className="hidden md:inline mx-2">&middot;</span>
{pipeline.description}
</Text>
)}
</Flex>
<Breadcrumbs pipeline={pipeline} />
</div>

<ManualRunDialog pipeline={pipeline} />
</Flex>
<ManualRunDialog pipeline={pipeline} />
</Flex>

<Breadcrumbs pipeline={pipeline} className="mt-4" />
</div>
}
>
<Grid numColsMd={2} numColsLg={3} className="gap-6 mt-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,36 @@ const TriggerView: React.FC = () => {
<Button
size="xs"
color="indigo"
variant="secondary"
icon={PlayIcon}
onClick={() => {
runPipelineMutation.mutateAsync()
}}
>
Run trigger
Run
</Button>
)

return (
<PageLayout
header={
<Flex className="items-start">
<div>
<Title>Trigger {trigger.name}</Title>
<Breadcrumbs pipeline={pipeline} trigger={trigger} />
</div>

{runTriggerButton}
</Flex>
<div>
<Flex className="items-start">
<Flex className="justify-start items-start md:items-center flex-col md:flex-row min-w-0">
<Title className="truncate max-w-full">Trigger {trigger.name}</Title>
{trigger.description && (
<Text className="truncate max-w-full">
<span className="hidden md:inline mx-2">&middot;</span>
{trigger.description}
</Text>
)}
</Flex>

{runTriggerButton}
</Flex>

<Breadcrumbs pipeline={pipeline} trigger={trigger} className="mt-4" />
</div>
}
>
<Grid numColsMd={2} numColsLg={3} className="gap-6 mt-6">
Expand Down
2 changes: 1 addition & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export default defineConfig({
},
plugins: [react(), splitVendorChunkPlugin()],
build: {
outDir: path.resolve('..', 'plombery', 'static'),
outDir: path.resolve('..', 'src', 'plombery', 'static'),
},
})
21 changes: 15 additions & 6 deletions src/plombery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from typing import List, Type
import logging
import os

from apscheduler.schedulers.base import SchedulerAlreadyRunningError
from pydantic import BaseModel
Expand All @@ -20,15 +21,15 @@
_logger.addHandler(logging.StreamHandler())


if os.getenv("DEBUG_APS"):
logging.basicConfig()
logging.getLogger("apscheduler").setLevel(logging.DEBUG)


class _Plombery:
def __init__(self) -> None:
self._apply_settings()

try:
orchestrator.start()
except SchedulerAlreadyRunningError:
pass

def _apply_settings(self):
for notification in settings.notifications or []:
self.add_notification_rule(notification)
Expand All @@ -51,6 +52,14 @@ async def __call__(self, scope, receive, send):
_app = _Plombery()


@app.on_event("startup")
def on_fastapi_start():
try:
orchestrator.start()
except SchedulerAlreadyRunningError:
pass


def get_app():
return _app

Expand Down
3 changes: 2 additions & 1 deletion src/plombery/orchestrator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta
from typing import Any, Dict, Tuple
from datetime import datetime, timedelta

from apscheduler.executors.asyncio import AsyncIOExecutor
from apscheduler.job import Job
Expand Down Expand Up @@ -37,6 +37,7 @@ def register_pipeline(self, pipeline: Pipeline):

self.scheduler.add_job(
id=job_id,
name=job_id,
func=run,
trigger=trigger.schedule,
kwargs=dict(pipeline=pipeline, trigger=trigger),
Expand Down

0 comments on commit b508884

Please sign in to comment.