Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions plugins/process-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export async function requestUserInput (
userContext = { ...userContext, ...tr }
changed = true
}
const sub = await getSubProcessesUserInput(space, target, userContext)
const sub = await getSubProcessesUserInput(execution, space, target, userContext)
if (sub !== undefined) {
userContext = { ...userContext, ...sub }
changed = true
Expand Down Expand Up @@ -543,6 +543,7 @@ function getEmptyContext (): ExecutionContext {
}

export async function getSubProcessesUserInput (
execution: Execution,
space: Ref<Space>,
transition: Transition,
userContext: ExecutionContext
Expand All @@ -552,8 +553,28 @@ export async function getSubProcessesUserInput (
if (action.methodId !== process.method.RunSubProcess) continue
const processId = action.params._id as Ref<Process>
if (processId === undefined) continue
const context = action.params.context ?? getEmptyContext()
const res = await newExecutionUserInput(processId, space, context)
const context: ExecutionContext = action.params.context ?? getEmptyContext()
const initTransition = getClient().getModel().findAllSync(process.class.Transition, {
process: processId,
from: null
})[0]
if (initTransition === undefined) continue
const card = action.params.card ?? execution.card
const client = getClient()
const mockExecution: Execution = {
_id: generateId(),
process: processId,
currentState: initTransition.to,
card,
rollback: [],
context,
status: ExecutionStatus.Active,
space,
_class: process.class.Execution,
modifiedOn: 0,
modifiedBy: client.user
}
const res = await newExecutionUserInput(processId, space, mockExecution)
if (action.context == null || res === undefined) continue
userContext[action.context._id] = res
changed = true
Expand Down
6 changes: 0 additions & 6 deletions server-plugins/process-resources/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,6 @@ export async function RunSubProcess (
}
}

// check card is exists
const exists = await control.client.findOne(cardPlugin.class.Card, { _id: _card })
if (exists === undefined) {
throw processError(process.error.ObjectNotFound, { _id: _card })
}

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const context = params.context ?? ({} as ExecutionContext)
const _id = generateId<Execution>()
Expand Down
6 changes: 6 additions & 0 deletions server-plugins/process-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export async function OnProcessToDoClose (txes: Tx[], control: TriggerControl):
event: events,
execution: todo.execution,
createdOn: tx.modifiedOn,
_id: tx._id,
context: {
todo
}
Expand Down Expand Up @@ -194,6 +195,7 @@ export async function OnCustomEvent (txes: Tx[], control: TriggerControl): Promi
execution: customEvent.execution,
createdOn: tx.modifiedOn,
card: customEvent.card,
_id: tx._id,
context: {
eventType: customEvent.eventType,
card
Expand All @@ -216,6 +218,7 @@ export async function OnExecutionCreate (txes: Tx[], control: TriggerControl): P
event: [process.trigger.OnExecutionStart],
execution: execution._id,
createdOn: tx.modifiedOn,
_id: tx._id,
context: {}
},
control
Expand All @@ -237,6 +240,7 @@ export async function OnProcessToDoRemove (txes: Tx[], control: TriggerControl):
event: [process.trigger.OnToDoRemove],
execution: removedTodo.execution,
createdOn: tx.modifiedOn,
_id: tx._id,
context: {
todo: removedTodo
}
Expand Down Expand Up @@ -266,6 +270,7 @@ export async function OnExecutionContinue (txes: Tx[], control: TriggerControl):
event: [process.trigger.OnExecutionContinue],
execution: execution._id,
createdOn: tx.modifiedOn,
_id: tx._id,
context: {}
},
control
Expand Down Expand Up @@ -476,6 +481,7 @@ export async function OnCardUpdate (txes: Tx[], control: TriggerControl): Promis
event: [process.trigger.OnCardUpdate, process.trigger.WhenFieldChanges],
card: cudTx.objectId,
createdOn: tx.modifiedOn,
_id: tx._id,
context: {
card: card[0],
operations: ops ?? {}
Expand Down
1 change: 1 addition & 0 deletions server-plugins/process/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type TransformFunc = (
) => Promise<any>

export interface ProcessMessage {
_id?: string
account: PersonId
createdOn: Timestamp
event: Ref<Trigger>[]
Expand Down
16 changes: 16 additions & 0 deletions services/process/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,24 @@ import { getClient, releaseClient, SERVICE_NAME } from './utils'
import config from './config'

const activeExecutions = new Set<Ref<Execution>>()
const processedMessages = new Map<string, number>()
const MAX_PROCESSED_MESSAGES = 1000

export async function messageHandler (record: ProcessMessage, ws: WorkspaceUuid, ctx: MeasureContext): Promise<void> {
if (record.account === core.account.ConfigUser) return
if (record._id !== undefined) {
if (processedMessages.has(record._id)) {
ctx.info('Skipping duplicate message', { _id: record._id, ws, record })
return
}
processedMessages.set(record._id, Date.now())
if (processedMessages.size > MAX_PROCESSED_MESSAGES) {
const first = processedMessages.keys().next().value
if (first !== undefined) {
processedMessages.delete(first)
}
}
}
try {
const client = new TxOperations(await getClient(ws), record.account)
try {
Expand Down Expand Up @@ -658,6 +673,7 @@ async function setTimer (control: ProcessControl, execution: Execution, transiti
const producer = queue.getProducer<TimeMachineMessage>(control.ctx, QueueTopic.TimeMachine)

const data: ProcessMessage = {
_id: `${execution._id}_${transition._id}`,
account: core.account.System,
event: [process.trigger.OnTime],
createdOn: Date.now(),
Expand Down
Loading