6 Commits

Author SHA1 Message Date
59a97e519e 0.0.34 2025-09-09 12:14:41 +02:00
b3d2877f0a Enhanced debugging and reduce verbose config logs
- Change trigger debugging from debug to info level for visibility
- Add trigger condition evaluation logging with doc status
- Reduce verbose plugin config logs that spam dev console
- Help customer diagnose trigger matching issues more effectively
2025-09-09 12:14:31 +02:00
c050ee835a 0.0.33 2025-09-09 11:58:50 +02:00
1f80028042 Add enhanced debugging for trigger matching
- Show detailed matching criteria for each trigger
- Display typeMatch, collectionMatch, operationMatch for debugging
- Help identify why triggers are not matching
- Assists in troubleshooting workflow execution issues
2025-09-09 11:58:45 +02:00
14d1ecf036 0.0.32 2025-09-09 11:38:50 +02:00
3749881d5f Fix workflow executor initialization timing issue
- Add lazy initialization when executor is not ready during hook execution
- Handles development hot-reloading scenarios where module registry resets
- Prevents 'Workflow executor not yet initialized' warnings
- Creates workflow executor on-demand when hooks fire before onInit
- Improved error handling and tracking for initialization failures

Resolves: Workflow executor timing issues in development environments
2025-09-09 11:38:40 +02:00
4 changed files with 48 additions and 18 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@xtr-dev/payload-workflows",
"version": "0.0.31",
"version": "0.0.34",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@xtr-dev/payload-workflows",
"version": "0.0.31",
"version": "0.0.34",
"license": "MIT",
"dependencies": {
"jsonpath-plus": "^10.3.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@xtr-dev/payload-automation",
"version": "0.0.31",
"version": "0.0.34",
"description": "PayloadCMS Automation Plugin - Comprehensive workflow automation system with visual workflow building, execution tracking, and step types",
"license": "MIT",
"type": "module",

View File

@@ -1029,17 +1029,24 @@ export class WorkflowExecutor {
}
}>
this.logger.debug({
this.logger.info({
workflowId: workflow.id,
workflowName: workflow.name,
triggerCount: triggers?.length || 0,
triggers: triggers?.map(t => ({
type: t.type,
parameters: t.parameters,
collection: t.parameters?.collection,
collectionSlug: t.parameters?.collectionSlug,
operation: t.parameters?.operation
}))
}, 'Checking workflow triggers')
operation: t.parameters?.operation,
// Debug matching criteria
typeMatch: t.type === 'collection-trigger',
collectionMatch: (t.parameters?.collection === collection || t.parameters?.collectionSlug === collection),
operationMatch: t.parameters?.operation === operation
})),
targetCollection: collection,
targetOperation: operation
}, 'Checking workflow triggers with detailed matching info')
const matchingTriggers = triggers?.filter(trigger =>
trigger.type === 'collection-trigger' &&
@@ -1083,7 +1090,7 @@ export class WorkflowExecutor {
// Check trigger condition if present
if (trigger.condition) {
this.logger.debug({
this.logger.info({
collection,
operation,
condition: trigger.condition,
@@ -1091,8 +1098,10 @@ export class WorkflowExecutor {
docFields: doc ? Object.keys(doc) : [],
previousDocId: (previousDoc as any)?.id,
workflowId: workflow.id,
workflowName: workflow.name
}, 'Evaluating collection trigger condition')
workflowName: workflow.name,
docStatus: (doc as any)?.status,
previousDocStatus: (previousDoc as any)?.status
}, 'Evaluating trigger condition before execution')
const conditionMet = this.evaluateCondition(trigger.condition, context)

View File

@@ -159,7 +159,7 @@ export const workflowsPlugin =
}
const collection = config.collections[collectionIndex]
logger.info(`Found collection '${triggerSlug}' - modifying its hooks...`)
logger.debug(`Found collection '${triggerSlug}' - modifying its hooks...`)
// Initialize hooks if needed
if (!collection.hooks) {
@@ -186,19 +186,40 @@ export const workflowsPlugin =
}, 'Collection automation hook triggered')
if (!registry.isInitialized) {
logger.warn('Workflow executor not yet initialized, skipping execution')
return undefined
logger.warn('Workflow executor not yet initialized, attempting lazy initialization')
try {
// Try to create executor if we have a payload instance
if (args.req?.payload) {
logger.info('Creating workflow executor via lazy initialization')
const { WorkflowExecutor } = await import('../core/workflow-executor.js')
const executor = new WorkflowExecutor(args.req.payload, logger)
setWorkflowExecutor(executor, logger)
logger.info('Lazy initialization successful')
} else {
logger.error('Cannot lazy initialize - no payload instance available')
await createFailedWorkflowRun(args, 'Workflow executor not initialized and lazy initialization failed - no payload instance', logger)
return undefined
}
} catch (error) {
logger.error('Lazy initialization failed:', error)
const errorMessage = error instanceof Error ? error.message : String(error)
await createFailedWorkflowRun(args, `Workflow executor lazy initialization failed: ${errorMessage}`, logger)
return undefined
}
}
if (!registry.executor) {
// Re-check registry after potential lazy initialization
const updatedRegistry = getExecutorRegistry()
if (!updatedRegistry.executor) {
logger.error('Workflow executor is null despite being marked as initialized')
// Create a failed workflow run to track this issue
await createFailedWorkflowRun(args, 'Executor not available', logger)
await createFailedWorkflowRun(args, 'Executor not available after initialization', logger)
return undefined
}
logger.debug('Executing triggered workflows...')
await registry.executor.executeTriggeredWorkflows(
await updatedRegistry.executor.executeTriggeredWorkflows(
args.collection.slug,
args.operation,
args.doc,
@@ -245,7 +266,7 @@ export const workflowsPlugin =
// Add the hook to the collection config
collection.hooks.afterChange.push(automationHook)
logger.info(`Added automation hook to '${triggerSlug}' - hook count: ${collection.hooks.afterChange.length}`)
logger.debug(`Added automation hook to '${triggerSlug}' - hook count: ${collection.hooks.afterChange.length}`)
}
}
@@ -254,7 +275,7 @@ export const workflowsPlugin =
}
const configLogger = getConfigLogger()
configLogger.info(`Configuring workflow plugin with ${Object.keys(pluginOptions.collectionTriggers || {}).length} collection triggers`)
configLogger.debug(`Configuring workflow plugin with ${Object.keys(pluginOptions.collectionTriggers || {}).length} collection triggers`)
// Generate cron tasks for workflows with cron triggers
generateCronTasks(config)