mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-11 01:03:23 +00:00
## Critical Fixes Implemented: ### 1. Hook Execution Reliability (src/plugin/index.ts) - Replaced fragile global variable pattern with proper dependency injection - Added structured executor registry with initialization tracking - Implemented proper logging using PayloadCMS logger instead of console - Added graceful handling for executor unavailability scenarios ### 2. Error Handling & Workflow Run Tracking - Fixed error swallowing in hook execution - Added createFailedWorkflowRun() to track hook execution failures - Improved error categorization and user-friendly error messages - Enhanced workflow run status tracking with detailed context ### 3. Enhanced HTTP Step (src/steps/) - Complete rewrite of HTTP request handler with enterprise features: - Multiple authentication methods (Bearer, Basic Auth, API Key) - Configurable timeouts and retry logic with exponential backoff - Comprehensive error handling for different failure scenarios - Support for all HTTP methods with proper request/response parsing - Request duration tracking and detailed logging ### 4. User Experience Improvements - Added StatusCell component with visual status indicators - Created ErrorDisplay component with user-friendly error explanations - Added WorkflowExecutionStatus component for real-time execution monitoring - Enhanced collections with better error display and conditional fields ### 5. Comprehensive Testing Suite - Added hook-reliability.spec.ts: Tests executor availability and concurrent execution - Added error-scenarios.spec.ts: Tests timeout, network, validation, and HTTP errors - Added webhook-triggers.spec.ts: Tests webhook endpoints, conditions, and concurrent requests - Fixed existing test to work with enhanced HTTP step schema ## Technical Improvements: - Proper TypeScript interfaces for all new components - Safe serialization handling for circular references - Comprehensive logging with structured data - Modular component architecture with proper exports - Enhanced collection schemas with conditional field visibility ## Impact: - Eliminates silent workflow execution failures - Provides clear error visibility for users - Makes HTTP requests production-ready with auth and retry capabilities - Significantly improves debugging and monitoring experience - Adds comprehensive test coverage for reliability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
159 lines
3.3 KiB
TypeScript
159 lines
3.3 KiB
TypeScript
import type { CollectionConfig } from 'payload'
|
|
|
|
export const WorkflowRunsCollection: CollectionConfig = {
|
|
slug: 'workflow-runs',
|
|
access: {
|
|
create: () => true,
|
|
delete: () => true,
|
|
read: () => true,
|
|
update: () => true,
|
|
},
|
|
admin: {
|
|
defaultColumns: ['workflow', 'status', 'triggeredBy', 'startedAt', 'duration'],
|
|
group: 'Automation',
|
|
pagination: {
|
|
defaultLimit: 50,
|
|
},
|
|
useAsTitle: 'id',
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'workflow',
|
|
type: 'relationship',
|
|
admin: {
|
|
description: 'Reference to the workflow that was executed',
|
|
},
|
|
relationTo: 'workflows',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'workflowVersion',
|
|
type: 'number',
|
|
admin: {
|
|
description: 'Version of the workflow that was executed',
|
|
},
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'status',
|
|
type: 'select',
|
|
admin: {
|
|
description: 'Current execution status',
|
|
components: {
|
|
Cell: '@/components/StatusCell'
|
|
}
|
|
},
|
|
defaultValue: 'pending',
|
|
options: [
|
|
{
|
|
label: '⏳ Pending',
|
|
value: 'pending',
|
|
},
|
|
{
|
|
label: '🔄 Running',
|
|
value: 'running',
|
|
},
|
|
{
|
|
label: '✅ Completed',
|
|
value: 'completed',
|
|
},
|
|
{
|
|
label: '❌ Failed',
|
|
value: 'failed',
|
|
},
|
|
{
|
|
label: '⏹️ Cancelled',
|
|
value: 'cancelled',
|
|
},
|
|
],
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'startedAt',
|
|
type: 'date',
|
|
admin: {
|
|
date: {
|
|
displayFormat: 'yyyy-MM-dd HH:mm:ss',
|
|
},
|
|
description: 'When execution began',
|
|
},
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'completedAt',
|
|
type: 'date',
|
|
admin: {
|
|
date: {
|
|
displayFormat: 'yyyy-MM-dd HH:mm:ss',
|
|
},
|
|
description: 'When execution finished',
|
|
},
|
|
},
|
|
{
|
|
name: 'duration',
|
|
type: 'number',
|
|
admin: {
|
|
description: 'Total execution time in milliseconds',
|
|
readOnly: true,
|
|
},
|
|
},
|
|
{
|
|
name: 'context',
|
|
type: 'json'
|
|
},
|
|
{
|
|
name: 'inputs',
|
|
type: 'json',
|
|
admin: {
|
|
description: 'Input data provided when the workflow was triggered',
|
|
},
|
|
defaultValue: {},
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'outputs',
|
|
type: 'json',
|
|
admin: {
|
|
description: 'Final output data from completed steps',
|
|
},
|
|
},
|
|
{
|
|
name: 'triggeredBy',
|
|
type: 'text',
|
|
admin: {
|
|
description: 'User, system, or trigger type that initiated execution',
|
|
},
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'steps',
|
|
type: 'json',
|
|
admin: {
|
|
description: 'Array of step execution results',
|
|
},
|
|
defaultValue: [],
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'error',
|
|
type: 'textarea',
|
|
admin: {
|
|
description: 'Error message if workflow execution failed',
|
|
condition: (_, siblingData) => siblingData?.status === 'failed',
|
|
components: {
|
|
Field: '@/components/ErrorDisplay'
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: 'logs',
|
|
type: 'json',
|
|
admin: {
|
|
description: 'Detailed execution logs',
|
|
},
|
|
defaultValue: [],
|
|
required: true,
|
|
},
|
|
],
|
|
}
|