How marsson/eventqueue works
Project type and purpose
• This is a Salesforce-centric automation framework implemented as an SFDX package (“Execution Queue”).
• It uses the Command design pattern in Apex to orchestrate critical business processes (inbound/outbound events, messaging) with retry, error handling, and extension capabilities.
File structure
• Top-level config files: sfdx-project.json, package.json, jest.config.js, manifest/package.xml.
• force-app/main/default:
• classes/: Apex command interfaces, abstract implementations, concrete commands, tests
• triggers/: two Apex triggers (EventConsumer.trigger, queueProcessor.trigger)
• objects/: custom objects Queue__c and platform event queueEvent__e definitions, plus custom metadata type Event_Configuration__mdt
• customMetadata/: metadata records mapping event types to Apex command classes
• flexipages, layouts, permissionsets, tabs: UI/perms for admin and running users
• aura, lwc: if any Lightning components are present (empty in this tree)
• config/: scratch org definition files for local development
• manifest/: package.xml for deployment
Extract insights from README
• Single custom object (“Queue__c”) drives execution via Apex triggers or scheduled job (every 5 minutes).
• Command pattern: ICommand interface, AbstractCommand base classes, CommandFactory to instantiate concrete commands.
• Custom metadata (Event_Configuration__mdt) to map event types to implementing Apex classes.
• Retry mechanism implemented via scheduled apex (JobPendingEvents, JobRetryEventProcessor, JobOldQueuedEvents).
• Optional performance boost through platform events (queueEvent__e).
a. Main components
• Salesforce Platform
• Queue__c Custom Object (the “queue table”)
• Apex Triggers:
– EventConsumer.trigger (platform event consumer)
– queueProcessor.trigger (on insert/update of Queue__c)
• Scheduled Apex Jobs:
– JobPendingEvents, JobRetryEventProcessor, JobOldQueuedEvents
• Command Framework:
– ICommand interface
– AbstractCommand, AbstractOutboundCommand, AbstractOutboundInboundCommand
– Concrete Commands (e.g., EventUnitTestCommand, MockThrowsExceptionCommand)
– CommandFactory
• Custom Metadata Type (Event_Configuration__mdt)
• Platform Event queueEvent__e (optional high-volume channel)
• External Systems (email/SMS providers, REST endpoints)
• UI/Configuration: Custom metadata setup UI, Lightning pages, permission sets
b. Relationships & interactions
1. User/Integration creates or updates a Queue__c record (“Queued” status).
2. queueProcessor.trigger fires → enqueues execution by instantiating correct ICommand via CommandFactory (using custom metadata mapping).
3. Concrete Command executes business logic (e.g., callout via RestProxy, create records), updates Queue__c status and logs errors.
4. On failure or retry count not exceeded, scheduled jobs (JobRetryEventProcessor) query Queue__c for failed or pending records and re-invoke command logic.
5. Optionally, platform event queueEvent__e is published/consumed by EventConsumer.trigger for async processing.
6. Custom metadata entries drive which command class to execute for each event type.
c. Architectural patterns & design principles
• Command pattern for pluggable business processes
• Trigger+Scheduling hybrid for immediate and batched retry execution
• Custom metadata for configuration-driven wiring
• Clear separation: Data (Queue__c), Orchestration (triggers/jobs), Execution (commands), Configuration (metadata)
d. Key technologies
• Salesforce Apex (classes, triggers, schedulable apex)
• Custom Objects & Platform Events
• SFDX and scratch org configs
• Lightning (LWC/Aura) for configuration UI
• Jest and Apex tests for code coverage