Skip to content

Commit

Permalink
Added Processor and Worker apps
Browse files Browse the repository at this point in the history
  • Loading branch information
anoopkarnik committed Aug 6, 2024
1 parent ec424d5 commit 213a048
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 147 deletions.
34 changes: 1 addition & 33 deletions apps/dashboard-app/actions/workflows/workflow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use server'

import {createWorkflow, editWorkflow, getNodesByWorkflowId, getWorkflowsByUserId, publishWorkflow, createNode, editNode, deleteNode, deleteWorkflow,getEventsById} from '@repo/prisma-db/repo/workflow';
import {createWorkflow, editWorkflow, getWorkflowsByUserId, publishWorkflow, deleteWorkflow,getEventsById} from '@repo/prisma-db/repo/workflow';
import {logger} from '@repo/winston-logger/index';

export const createWorkflowAction = async ({name,description,userId}:any) => {
Expand Down Expand Up @@ -30,38 +30,6 @@ export const deleteFlow= async (workflowId:string) => {
await deleteWorkflow(workflowId);
}

export const getNodes = async (workflowId:string) => {
const workflow = await getNodesByWorkflowId(workflowId);
const name = workflow?.name || 'Untitled';
const nodes = workflow?.nodes;
const description = workflow?.description || '';
const publish = workflow?.publish || false;
let trigger = undefined
let actions:any = [];
if (name && nodes) {
trigger = nodes.find((node:any) => node.type === 'Trigger');
actions = nodes.filter((node:any) => node.type === 'Action');
}

return {name,description,publish,trigger,actions};
}

export const addNodeToWorkflow = async ({name,description,workflowId,type,userId,actionType,subActionType,actionData}:any) => {
logger.info('Adding node to workflow',name,description,workflowId,type,userId,actionType,subActionType,actionData);
const node:any = await createNode({name,description,workflowId,type,userId,actionType,subActionType,actionData});
return node;
}

export const editNodeInWorkflow = async ({id,name,description,workflowId,type,userId,actionType,subActionType,actionData}:any) => {
logger.info('Editing node in workflow',id,name,description,workflowId,type,userId,actionType,subActionType,actionData);
const node:any = await editNode({id,name,description,workflowId,type,userId,actionType,subActionType,actionData});
return node;
}

export const deleteNodeInWorkflow = async (id:string) => {
await deleteNode(id);
return 'Node deleted';
}

export const getEventsByWorkflowId = async (workflowId:string) => {
const events:any = await getEventsById(workflowId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TRIGGER_TYPES, ACTION_TYPES } from '../../../../../../lib/constant';
import 'reactflow/dist/style.css';
import { Card,CardHeader,CardTitle,CardFooter,CardDescription,CardContent } from '@repo/ui/molecules/shadcn/Card';
import { useParams, useRouter } from 'next/navigation';
import { deleteNodeInWorkflow, editFlow, getNodes, publishFlow } from '../../../../../../actions/workflows/workflow';
import { editFlow, publishFlow } from '../../../../../../actions/workflows/workflow';
import { EditorContext } from '../../../../../../providers/editor-provider';
import { ArrowBigDownDash, Edit2Icon, TrashIcon } from 'lucide-react';
import NodeSheet from './NodeSheet';
Expand All @@ -33,14 +33,6 @@ const Nodes = () => {
useEffect(() => {
const refreshNodes = async () => {
setLoading(true);
const {name,description,publish,trigger,actions} = await getNodes(editorId as string);
setLoading(false);
console.log('Setting nodes',name,description,publish,trigger,actions);
editor.setActions(actions);
editor.setTrigger(trigger);
editor.setName(name);
editor.setDescription(description);
editor.setPublish(publish);
}
refreshNodes();
},[editorId] )
Expand All @@ -56,7 +48,6 @@ const Nodes = () => {
}

const handleDelete = async (id:string) => {
await deleteNodeInWorkflow(id);
router.refresh();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
import { Textarea } from '@repo/ui/molecules/shadcn/TextArea'
import React, { useContext } from 'react'
import { useForm } from 'react-hook-form';
import { addNodeToWorkflow, editNodeInWorkflow } from '../../../../../../../actions/workflows/workflow';
import { getSession } from 'next-auth/react';
import { useParams } from 'next/navigation';
import { EditorContext } from '../../../../../../../providers/editor-provider';
Expand All @@ -23,13 +22,7 @@ const Schedule = ({type,actionType,subActionType,node}:any) => {
let name = `${type}-${actionType}-${subActionType}`
let description = `${type}-${actionType}-${subActionType}`
let id = node?.id

if (node.length ==0){
const node = await addNodeToWorkflow({name,description,workflowId: editorId,type,userId,actionType,subActionType,actionData:JSON.stringify(data)})
}
else{
const node = await editNodeInWorkflow({id,name,description,workflowId: editorId,type,userId,actionType,subActionType,actionData:JSON.stringify(data)})
}


if (type === 'Trigger') {
editor.setTrigger(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
import { Textarea } from '@repo/ui/molecules/shadcn/TextArea'
import React, { useContext } from 'react'
import { useForm } from 'react-hook-form';
import { addNodeToWorkflow, editNodeInWorkflow } from '../../../../../../../actions/workflows/workflow';
import { getSession } from 'next-auth/react';
import { useParams } from 'next/navigation';
import { EditorContext } from '../../../../../../../providers/editor-provider';
Expand All @@ -23,13 +22,6 @@ const Webhook = ({type,actionType,subActionType,node}:any) => {
let name = `${type}-${actionType}-${subActionType}`
let description = `${type}-${actionType}-${subActionType}`
let id = node?.id

if (node.length ==0){
const node = await addNodeToWorkflow({name,description,workflowId: editorId,type,userId,actionType,subActionType,actionData:JSON.stringify(data)})
}
else{
const node = await editNodeInWorkflow({id,name,description,workflowId: editorId,type,userId,actionType,subActionType,actionData:JSON.stringify(data)})
}

if (type === 'Trigger') {
editor.setTrigger(node)
Expand Down
101 changes: 13 additions & 88 deletions packages/prisma-db/src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ export const getWorkflowsByUserId = async (userId: string) => {
const workflows = await db.workflow.findMany({
where:{
userId
}
},
include:{
actions: {
include:{
type: true
}
},
trigger: {
include:{
type: true
}
}
},
})
return workflows;
}
Expand All @@ -48,17 +60,6 @@ export const editWorkflow = async (workflowId: string, name: string, description
})
}

export const startAction = async (id:string,actionId: string) => {
const node = await db.node.update({
where:{
id
},
data:{
actionId
}
})
return node;
}



Expand Down Expand Up @@ -88,74 +89,6 @@ export const updateWorkflowLastRun = async (workflowId: string, lastRun: string)
}


export const getNodesByWorkflowId = async (id: string) => {
const nodes = await db.workflow.findFirst({
where:{
id
},
include:{
nodes: true
}
})
return nodes;
}

export const getActiveWorkflows = async () => {
const workflows = await db.workflow.findMany({
where:{
publish: true
},
include:{
nodes: true
}
})
if (workflows){
return workflows;
}
else{
return [];

}
}

export const createNode = async ({name,description,workflowId,type,userId,actionType,subActionType,actionData,actionId}:any) => {
const node = await db.node.create({
data:{
name,
description,
workflowId,
type,
userId,
actionType,
subActionType,
actionData,
actionId
}
})
return node;
}

export const editNode = async ({id,name,description,workflowId,type,userId,actionType,subActionType,actionData,actionId}:any) => {
const node = await db.node.update({
where: {
id
},
data:{
name,
description,
workflowId,
type,
userId,
actionType,
subActionType,
actionData,
actionId
}
})
return node;
}


export const deleteWorkflow = async (workflowId: string) => {
const workflow = await db.workflow.delete({
where:{
Expand All @@ -165,14 +98,6 @@ export const deleteWorkflow = async (workflowId: string) => {
return workflow;
}

export const deleteNode = async (nodeId: string) => {
const node = await db.node.delete({
where:{
id: nodeId
}
})
return node;
}

export const createEvent = async(workflowId:string, status:string, metadata:any) => {
await db.$transaction( async (tx) => {
Expand Down

0 comments on commit 213a048

Please sign in to comment.