Skip to content

Commit

Permalink
Merge pull request #11 from riverqueue/bg-workflow-supervisorless-cha…
Browse files Browse the repository at this point in the history
…nges

Workflow changes
  • Loading branch information
bgentry authored Jun 9, 2024
2 parents 29d44fe + f89470a commit 6a05cf0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 45 deletions.
21 changes: 5 additions & 16 deletions api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ type StatesAndCountsResponse struct {
}

type WorkflowGetResponse struct {
Supervisor *RiverJob `json:"supervisor"`
Tasks []RiverJob `json:"tasks"`
Tasks []RiverJob `json:"tasks"`
}

func (a *apiHandler) WorkflowGet(rw http.ResponseWriter, req *http.Request) {
Expand All @@ -372,13 +371,10 @@ func (a *apiHandler) WorkflowGet(rw http.ResponseWriter, req *http.Request) {
return
}

const workflowSupervisorJobKind = "WorkflowSupervisor"

dbJobs, err := a.queries.JobListWorkflow(ctx, db.JobListWorkflowParams{
PaginationLimit: 1000,
PaginationOffset: 0,
WorkflowSupervisorKind: workflowSupervisorJobKind,
WorkflowID: workflowID,
PaginationLimit: 1000,
PaginationOffset: 0,
WorkflowID: workflowID,
})
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
Expand All @@ -393,14 +389,7 @@ func (a *apiHandler) WorkflowGet(rw http.ResponseWriter, req *http.Request) {
jobs := internalJobsToSerializableJobs(dbJobs)

resp := WorkflowGetResponse{}
if len(jobs) != 0 {
startIndex := 0
if jobs[0].Kind == workflowSupervisorJobKind {
resp.Supervisor = &jobs[0]
startIndex = 1
}
resp.Tasks = jobs[startIndex:]
}
resp.Tasks = jobs

if err = json.NewEncoder(rw).Encode(resp); err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
Expand Down
1 change: 0 additions & 1 deletion internal/db/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ FROM
WHERE
metadata @> jsonb_build_object('workflow_id', @workflow_id::text)
ORDER BY
kind = @workflow_supervisor_kind::text DESC,
id ASC
LIMIT @pagination_limit::integer
OFFSET @pagination_offset::bigint;
Expand Down
19 changes: 6 additions & 13 deletions internal/db/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions ui/src/components/WorkflowDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type WorkflowDetailProps = {
};

export default function WorkflowDetail({ workflow }: WorkflowDetailProps) {
const { supervisor, tasks } = workflow;
const { tasks } = workflow;
return (
<>
<header>
Expand All @@ -25,17 +25,15 @@ export default function WorkflowDetail({ workflow }: WorkflowDetailProps) {
</div>
<p className="ml-7 mt-2 text-base leading-6 text-slate-600 dark:text-slate-400">
ID:{" "}
<span className="font-mono">
{supervisor.metadata.workflow_id}
</span>
<span className="font-mono">{tasks[0].metadata.workflow_id}</span>
{/* {capitalize(job.state)} */}
</p>
</div>
</div>
</header>

<div className="mx-auto h-[32rem] w-full px-4 sm:px-6 lg:px-8">
<WorkflowDiagram supervisor={supervisor} tasks={tasks} />
<div className="mx-auto h-[calc(100%-9rem)] w-full">
<WorkflowDiagram tasks={tasks} />
</div>
</>
);
Expand Down
12 changes: 7 additions & 5 deletions ui/src/components/WorkflowDiagram.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReactFlow from "reactflow";
import ReactFlow, { MiniMap } from "reactflow";
import type { Edge, Node, NodeTypes, Position } from "reactflow";
import dagre from "@dagrejs/dagre";

Expand All @@ -10,7 +10,6 @@ import { JobState } from "@services/types";
import WorkflowNode, { WorkflowNodeData } from "@components/WorkflowNode";

type WorkflowDetailProps = {
supervisor: JobWithKnownMetadata;
tasks: JobWithKnownMetadata[];
};

Expand All @@ -21,7 +20,7 @@ type nameToJobMap = {
const dagreGraph = new dagre.graphlib.Graph();
dagreGraph.setDefaultEdgeLabel(() => ({}));

const nodeWidth = 250;
const nodeWidth = 208;
const nodeHeight = 180;

const getLayoutedElements = (
Expand All @@ -35,7 +34,7 @@ const getLayoutedElements = (
edgesep: 100,
nodesep: 80,
rankdir: direction,
ranksep: 80,
ranksep: 100,
});

nodes.forEach((node) => {
Expand Down Expand Up @@ -164,12 +163,15 @@ export default function WorkflowDiagram({ tasks }: WorkflowDetailProps) {
return (
<div className="size-full">
<ReactFlow
defaultViewport={{ x: 32, y: 32, zoom: 1 }}
edges={layoutedEdges}
// fitView
nodeTypes={nodeTypes}
nodes={layoutedNodes}
proOptions={{ hideAttribution: true }}
/>
>
<MiniMap nodeStrokeWidth={3} pannable zoomable />
</ReactFlow>
</div>
);
}
2 changes: 1 addition & 1 deletion ui/src/components/WorkflowNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const WorkflowNode = memo(
const { hasDownstreamDeps, hasUpstreamDeps, job } = data;

return (
<div className="w-60 overflow-hidden rounded-xl border-2 border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-800">
<div className="w-52 overflow-hidden rounded-xl border-2 border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-800">
<Handle
type="target"
position={Position.Left}
Expand Down
3 changes: 0 additions & 3 deletions ui/src/services/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { JobFromAPI, JobWithKnownMetadata, apiJobToJob } from "@services/jobs";
// string dates instead of Date objects and keys as snake_case instead of
// camelCase.
type WorkflowFromAPI = {
supervisor: JobFromAPI;
tasks: JobFromAPI[];
};

export type Workflow = {
supervisor: JobWithKnownMetadata;
tasks: JobWithKnownMetadata[];
};

Expand All @@ -34,6 +32,5 @@ export const getWorkflow: QueryFunction<Workflow, GetWorkflowKey> = async ({
};

const apiWorkflowToWorkflow = (job: WorkflowFromAPI): Workflow => ({
supervisor: apiJobToJob(job.supervisor) as JobWithKnownMetadata,
tasks: job.tasks.map(apiJobToJob) as JobWithKnownMetadata[],
});

0 comments on commit 6a05cf0

Please sign in to comment.