handlers

package
v0.0.0-...-bcf15ee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package handlers provides workflow handling capabilities

Package handlers provides workflow handling capabilities

Index

Constants

View Source
const (
	IntegrationWorkflowHandlerName = "workflow.handler.integration"
)

Standard handler name constants

View Source
const (
	MessagingWorkflowHandlerName = "workflow.handler.messaging"
)

Standard handler name constants

View Source
const (
	StateMachineWorkflowHandlerName = "workflow.handler.statemachine"
)

Standard handler name

Variables

View Source
var PatchAppServiceCalls = func(app modular.Application) {

}

PatchAppServiceCalls patches common calls in the application's handler functions This is a temporary solution until the handlers are updated to use the new API

Functions

func CreateMockApplication

func CreateMockApplication() modular.Application

CreateMockApplication creates a mock application for testing

func FixEventHandlerGetService

func FixEventHandlerGetService(app modular.Application, name string) interface{}

FixEventHandlerGetService fixes the GetService calls in events.go

func FixHTTPHandlerService

func FixHTTPHandlerService(app modular.Application, name string) interface{}

FixHTTPHandlerService fixes app.Service calls in http.go

func FixMessagingHandlerServices

func FixMessagingHandlerServices(app modular.Application) map[string]interface{}

FixMessagingHandlerServices fixes app.Services calls in messaging.go

func GetEventProcessor

func GetEventProcessor(app modular.Application) interface{}

GetEventProcessor is a utility function to get the event processor service

func GetService

func GetService(app modular.Application, name string) interface{}

GetService is a utility function to get services from an application

func NewServiceRegistryAdapter

func NewServiceRegistryAdapter(app modular.Application) *applicationServiceRegistryAdapter

NewServiceRegistryAdapter creates an adapter for service registry operations

func RegisterEventProcessor

func RegisterEventProcessor(app modular.Application, processor *module.EventProcessor) error

RegisterEventProcessor creates and registers an EventProcessorAdapter for the given event processor

Types

type ApplicationHelper

type ApplicationHelper struct {
	// contains filtered or unexported fields
}

ApplicationHelper extends the modular.Application with useful service methods

func NewApplicationHelper

func NewApplicationHelper(app modular.Application) *ApplicationHelper

NewApplicationHelper creates a helper for application service access

func WithHelper

func WithHelper(app modular.Application) *ApplicationHelper

WithHelper returns the helper or creates one if needed

func (*ApplicationHelper) Service

func (h *ApplicationHelper) Service(name string) interface{}

Service provides access to a named service

func (*ApplicationHelper) Services

func (h *ApplicationHelper) Services() map[string]interface{}

Services returns all cached services

type EventAdapterConfig

type EventAdapterConfig struct {
	Broker      string   `json:"broker" yaml:"broker"`
	Topics      []string `json:"topics" yaml:"topics"`
	EventType   string   `json:"eventType" yaml:"eventType"`
	SourceIdKey string   `json:"sourceIdKey,omitempty" yaml:"sourceIdKey,omitempty"`
	CorrelIdKey string   `json:"correlIdKey,omitempty" yaml:"correlIdKey,omitempty"`
}

EventAdapterConfig represents an adapter between message broker and event processor

type EventHandlerConfig

type EventHandlerConfig struct {
	PatternID string                 `json:"patternId" yaml:"patternId"`
	Handler   string                 `json:"handler" yaml:"handler"`
	Config    map[string]interface{} `json:"config,omitempty" yaml:"config,omitempty"`
}

EventHandlerConfig represents event handler configuration

type EventPatternConfig

type EventPatternConfig struct {
	PatternID    string                 `json:"patternId" yaml:"patternId"`
	EventTypes   []string               `json:"eventTypes" yaml:"eventTypes"`
	WindowTime   string                 `json:"windowTime" yaml:"windowTime"`
	Condition    string                 `json:"condition" yaml:"condition"`
	MinOccurs    int                    `json:"minOccurs" yaml:"minOccurs"`
	MaxOccurs    int                    `json:"maxOccurs" yaml:"maxOccurs"`
	OrderMatters bool                   `json:"orderMatters" yaml:"orderMatters"`
	ExtraParams  map[string]interface{} `json:"extraParams,omitempty" yaml:"extraParams,omitempty"`
}

EventPatternConfig represents event pattern configuration

type EventProcessorAdapter

type EventProcessorAdapter struct {
	Processor *module.EventProcessor
}

EventProcessorAdapter adapts an EventProcessor to ensure interface compatibility

func (*EventProcessorAdapter) HandleEvent

func (a *EventProcessorAdapter) HandleEvent(ctx context.Context, event interface{}) error

HandleEvent implements the expected interface for EventProcessor

type EventWorkflowConfig

type EventWorkflowConfig struct {
	Processor string               `json:"processor" yaml:"processor"`
	Patterns  []EventPatternConfig `json:"patterns" yaml:"patterns"`
	Handlers  []EventHandlerConfig `json:"handlers" yaml:"handlers"`
	Adapters  []EventAdapterConfig `json:"adapters,omitempty" yaml:"adapters,omitempty"`
}

EventWorkflowConfig represents event workflow configuration

type EventWorkflowHandler

type EventWorkflowHandler struct{}

EventWorkflowHandler handles event-driven workflows with complex event processing

func NewEventWorkflowHandler

func NewEventWorkflowHandler() *EventWorkflowHandler

NewEventWorkflowHandler creates a new event workflow handler

func (*EventWorkflowHandler) CanHandle

func (h *EventWorkflowHandler) CanHandle(workflowType string) bool

CanHandle returns true if this handler can process the given workflow type

func (*EventWorkflowHandler) ConfigureWorkflow

func (h *EventWorkflowHandler) ConfigureWorkflow(app modular.Application, workflowConfig interface{}) error

ConfigureWorkflow sets up the workflow from configuration

func (*EventWorkflowHandler) ExecuteWorkflow

func (h *EventWorkflowHandler) ExecuteWorkflow(ctx context.Context, workflowType string, action string, data map[string]interface{}) (map[string]interface{}, error)

ExecuteWorkflow executes a workflow with the given action and input data

type HTTPRouteConfig

type HTTPRouteConfig struct {
	Method      string                 `json:"method" yaml:"method"`
	Path        string                 `json:"path" yaml:"path"`
	Handler     string                 `json:"handler" yaml:"handler"`
	Middlewares []string               `json:"middlewares,omitempty" yaml:"middlewares,omitempty"`
	Config      map[string]interface{} `json:"config,omitempty" yaml:"config,omitempty"`
}

HTTPRouteConfig represents a route configuration in HTTP workflow

type HTTPWorkflowHandler

type HTTPWorkflowHandler struct{}

HTTPWorkflowHandler handles HTTP-based workflows

func NewHTTPWorkflowHandler

func NewHTTPWorkflowHandler() *HTTPWorkflowHandler

NewHTTPWorkflowHandler creates a new HTTP workflow handler

func (*HTTPWorkflowHandler) CanHandle

func (h *HTTPWorkflowHandler) CanHandle(workflowType string) bool

CanHandle returns true if this handler can process the given workflow type

func (*HTTPWorkflowHandler) ConfigureWorkflow

func (h *HTTPWorkflowHandler) ConfigureWorkflow(app modular.Application, workflowConfig interface{}) error

ConfigureWorkflow sets up the workflow from configuration

func (*HTTPWorkflowHandler) ExecuteWorkflow

func (h *HTTPWorkflowHandler) ExecuteWorkflow(ctx context.Context, workflowType string, action string, data map[string]interface{}) (map[string]interface{}, error)

ExecuteWorkflow executes a workflow with the given action and input data

type IntegrationConnector

type IntegrationConnector struct {
	Name   string                 `json:"name" yaml:"name"`
	Type   string                 `json:"type" yaml:"type"`
	Config map[string]interface{} `json:"config" yaml:"config"`
}

IntegrationConnector represents a connector configuration

type IntegrationStep

type IntegrationStep struct {
	Name       string                 `json:"name" yaml:"name"`
	Connector  string                 `json:"connector" yaml:"connector"`
	Action     string                 `json:"action" yaml:"action"`
	Input      map[string]interface{} `json:"input,omitempty" yaml:"input,omitempty"`
	Transform  string                 `json:"transform,omitempty" yaml:"transform,omitempty"`
	OnSuccess  string                 `json:"onSuccess,omitempty" yaml:"onSuccess,omitempty"`
	OnError    string                 `json:"onError,omitempty" yaml:"onError,omitempty"`
	RetryCount int                    `json:"retryCount,omitempty" yaml:"retryCount,omitempty"`
	RetryDelay string                 `json:"retryDelay,omitempty" yaml:"retryDelay,omitempty"`
}

IntegrationStep represents a step in an integration workflow

type IntegrationWorkflowConfig

type IntegrationWorkflowConfig struct {
	Registry   string                 `json:"registry" yaml:"registry"`
	Connectors []IntegrationConnector `json:"connectors" yaml:"connectors"`
	Steps      []IntegrationStep      `json:"steps" yaml:"steps"`
}

IntegrationWorkflowConfig represents an integration workflow configuration

type IntegrationWorkflowHandler

type IntegrationWorkflowHandler struct {
	// contains filtered or unexported fields
}

IntegrationWorkflowHandler handles integration workflows

func NewIntegrationWorkflowHandler

func NewIntegrationWorkflowHandler() *IntegrationWorkflowHandler

NewIntegrationWorkflowHandler creates a new integration workflow handler

func NewIntegrationWorkflowHandlerWithNamespace

func NewIntegrationWorkflowHandlerWithNamespace(namespace module.ModuleNamespaceProvider) *IntegrationWorkflowHandler

NewIntegrationWorkflowHandlerWithNamespace creates a new integration workflow handler with namespace support

func (*IntegrationWorkflowHandler) CanHandle

func (h *IntegrationWorkflowHandler) CanHandle(workflowType string) bool

CanHandle returns true if this handler can process the given workflow type

func (*IntegrationWorkflowHandler) ConfigureWorkflow

func (h *IntegrationWorkflowHandler) ConfigureWorkflow(app modular.Application, workflowConfig interface{}) error

ConfigureWorkflow sets up the workflow from configuration

func (*IntegrationWorkflowHandler) ExecuteIntegrationWorkflow

func (h *IntegrationWorkflowHandler) ExecuteIntegrationWorkflow(
	ctx context.Context,
	registry module.IntegrationRegistry,
	steps []IntegrationStep,
	initialContext map[string]interface{},
) (map[string]interface{}, error)

ExecuteIntegrationWorkflow executes a sequence of integration steps

func (*IntegrationWorkflowHandler) ExecuteWorkflow

func (h *IntegrationWorkflowHandler) ExecuteWorkflow(ctx context.Context, workflowType string, action string, data map[string]interface{}) (map[string]interface{}, error)

ExecuteWorkflow executes a workflow with the given action and input data

func (*IntegrationWorkflowHandler) Init

Init initializes the handler

func (*IntegrationWorkflowHandler) Name

Name returns the name of this handler

func (*IntegrationWorkflowHandler) Start

Start starts the handler

func (*IntegrationWorkflowHandler) Stop

Stop stops the handler

type MessagingWorkflowHandler

type MessagingWorkflowHandler struct {
	// contains filtered or unexported fields
}

MessagingWorkflowHandler handles message-based workflows

func NewMessagingWorkflowHandler

func NewMessagingWorkflowHandler() *MessagingWorkflowHandler

NewMessagingWorkflowHandler creates a new messaging workflow handler

func NewMessagingWorkflowHandlerWithNamespace

func NewMessagingWorkflowHandlerWithNamespace(namespace workflowmodule.ModuleNamespaceProvider) *MessagingWorkflowHandler

NewMessagingWorkflowHandlerWithNamespace creates a messaging workflow handler with namespace support

func (*MessagingWorkflowHandler) CanHandle

func (h *MessagingWorkflowHandler) CanHandle(workflowType string) bool

CanHandle returns true if this handler can process the given workflow type

func (*MessagingWorkflowHandler) ConfigureWorkflow

func (h *MessagingWorkflowHandler) ConfigureWorkflow(app modular.Application, workflowConfig interface{}) error

ConfigureWorkflow sets up the workflow from configuration

func (*MessagingWorkflowHandler) ExecuteWorkflow

func (h *MessagingWorkflowHandler) ExecuteWorkflow(ctx context.Context, workflowType string, action string, data map[string]interface{}) (map[string]interface{}, error)

ExecuteWorkflow executes a workflow with the given action and input data

func (*MessagingWorkflowHandler) Name

func (h *MessagingWorkflowHandler) Name() string

Name returns the name of this handler

type MockEngine

type MockEngine struct {
	// contains filtered or unexported fields
}

MockEngine is a simplified engine for testing

func NewTestEngine

func NewTestEngine(app modular.Application) *MockEngine

NewTestEngine creates a workflow engine for testing

func (*MockEngine) AddModuleType

func (e *MockEngine) AddModuleType(name string, creator interface{})

AddModuleType adds a module type to the mock engine

func (*MockEngine) BuildFromConfig

func (e *MockEngine) BuildFromConfig(cfg interface{}) error

BuildFromConfig simulates building a workflow from config

func (*MockEngine) RegisterHandler

func (e *MockEngine) RegisterHandler(name string, handler interface{})

RegisterHandler registers a handler with the mock engine

func (*MockEngine) Start

func (e *MockEngine) Start(ctx context.Context) error

Start simulates starting the engine

func (*MockEngine) Stop

func (e *MockEngine) Stop(ctx context.Context) error

Stop simulates stopping the engine

type ScheduledJobConfig

type ScheduledJobConfig struct {
	Scheduler string                 `json:"scheduler" yaml:"scheduler"`
	Job       string                 `json:"job" yaml:"job"`
	Config    map[string]interface{} `json:"config,omitempty" yaml:"config,omitempty"`
}

ScheduledJobConfig represents a job scheduler configuration

type SchedulerTestHelper

type SchedulerTestHelper struct {
	App modular.Application
}

SchedulerTestHelper contains utilities for testing schedulers

func NewSchedulerTestHelper

func NewSchedulerTestHelper(app modular.Application) *SchedulerTestHelper

NewSchedulerTestHelper creates a new scheduler test helper

func (*SchedulerTestHelper) RegisterTestJob

func (h *SchedulerTestHelper) RegisterTestJob(name string, fn func(ctx context.Context) error) *TestJob

RegisterTestJob registers a test job with the application

func (*SchedulerTestHelper) TriggerJobExecution

func (h *SchedulerTestHelper) TriggerJobExecution(ctx context.Context, jobName string) error

TriggerJobExecution manually triggers execution of a job

type SchedulerWorkflowHandler

type SchedulerWorkflowHandler struct{}

SchedulerWorkflowHandler handles scheduler-based workflows

func NewSchedulerWorkflowHandler

func NewSchedulerWorkflowHandler() *SchedulerWorkflowHandler

NewSchedulerWorkflowHandler creates a new scheduler workflow handler

func (*SchedulerWorkflowHandler) CanHandle

func (h *SchedulerWorkflowHandler) CanHandle(workflowType string) bool

CanHandle returns true if this handler can process the given workflow type

func (*SchedulerWorkflowHandler) ConfigureWorkflow

func (h *SchedulerWorkflowHandler) ConfigureWorkflow(app modular.Application, workflowConfig interface{}) error

ConfigureWorkflow sets up the workflow from configuration

func (*SchedulerWorkflowHandler) ExecuteWorkflow

func (h *SchedulerWorkflowHandler) ExecuteWorkflow(ctx context.Context, workflowType string, action string, data map[string]interface{}) (map[string]interface{}, error)

ExecuteWorkflow executes a workflow with the given action and input data

type ServiceAccessor

type ServiceAccessor interface {
	Service(name string) interface{}
	Services() map[string]interface{}
}

ServiceAccessor provides methods for accessing services

type ServiceHelper

type ServiceHelper struct {
	App modular.Application
}

ServiceHelper helps with service access in handlers

func GetServiceHelper

func GetServiceHelper(app modular.Application) *ServiceHelper

GetServiceHelper returns a helper for an application

func New

New creates a new service helper for an application

func (*ServiceHelper) GetService

func (s *ServiceHelper) GetService(name string, dest interface{}) error

GetService implements the GetService method

func (*ServiceHelper) Init

func (s *ServiceHelper) Init() error

Init initializes the service helper

func (*ServiceHelper) RegisterService

func (s *ServiceHelper) RegisterService(name string, service interface{}) error

RegisterService implements the RegisterService method

func (*ServiceHelper) Service

func (s *ServiceHelper) Service(name string) interface{}

Service retrieves a service by name

func (*ServiceHelper) Services

func (s *ServiceHelper) Services() map[string]interface{}

Services returns all services in the application

func (*ServiceHelper) SvcRegistry

func (s *ServiceHelper) SvcRegistry() map[string]interface{}

SvcRegistry implements the SvcRegistry method

type StateMachineDefinition

type StateMachineDefinition struct {
	Name         string                            `json:"name" yaml:"name"`
	Description  string                            `json:"description,omitempty" yaml:"description,omitempty"`
	InitialState string                            `json:"initialState" yaml:"initialState"`
	States       map[string]StateMachineState      `json:"states" yaml:"states"`
	Transitions  map[string]StateMachineTransition `json:"transitions" yaml:"transitions"`
}

StateMachineDefinition represents a state machine definition

type StateMachineHookConfig

type StateMachineHookConfig struct {
	WorkflowType string   `json:"workflowType" yaml:"workflowType"`
	Transitions  []string `json:"transitions,omitempty" yaml:"transitions,omitempty"`
	FromStates   []string `json:"fromStates,omitempty" yaml:"fromStates,omitempty"`
	ToStates     []string `json:"toStates,omitempty" yaml:"toStates,omitempty"`
	Handler      string   `json:"handler" yaml:"handler"`
}

StateMachineHookConfig represents a hook configuration for state transitions

type StateMachineState

type StateMachineState struct {
	Name        string                 `json:"name" yaml:"name"`
	Description string                 `json:"description,omitempty" yaml:"description,omitempty"`
	IsFinal     bool                   `json:"isFinal" yaml:"isFinal"`
	IsError     bool                   `json:"isError" yaml:"isError"`
	Data        map[string]interface{} `json:"data,omitempty" yaml:"data,omitempty"`
}

StateMachineState represents a workflow state

type StateMachineTransition

type StateMachineTransition struct {
	FromState     string                 `json:"fromState" yaml:"fromState"`
	ToState       string                 `json:"toState" yaml:"toState"`
	Condition     string                 `json:"condition,omitempty" yaml:"condition,omitempty"`
	AutoTransform bool                   `json:"autoTransform" yaml:"autoTransform"`
	Data          map[string]interface{} `json:"data,omitempty" yaml:"data,omitempty"`
}

StateMachineTransition represents a transition between states

type StateMachineWorkflowConfig

type StateMachineWorkflowConfig struct {
	Engine      string                   `json:"engine" yaml:"engine"`
	Definitions []StateMachineDefinition `json:"definitions" yaml:"definitions"`
	Hooks       []StateMachineHookConfig `json:"hooks,omitempty" yaml:"hooks,omitempty"`
}

StateMachineWorkflowConfig represents a state machine workflow configuration

type StateMachineWorkflowHandler

type StateMachineWorkflowHandler struct {
	// contains filtered or unexported fields
}

StateMachineWorkflowHandler handles state machine workflows

func NewStateMachineWorkflowHandler

func NewStateMachineWorkflowHandler() *StateMachineWorkflowHandler

NewStateMachineWorkflowHandler creates a new state machine workflow handler

func NewStateMachineWorkflowHandlerWithNamespace

func NewStateMachineWorkflowHandlerWithNamespace(namespace module.ModuleNamespaceProvider) *StateMachineWorkflowHandler

NewStateMachineWorkflowHandlerWithNamespace creates a state machine workflow handler with namespace support

func (*StateMachineWorkflowHandler) CanHandle

func (h *StateMachineWorkflowHandler) CanHandle(workflowType string) bool

CanHandle returns true if this handler can process the given workflow type

func (*StateMachineWorkflowHandler) ConfigureWorkflow

func (h *StateMachineWorkflowHandler) ConfigureWorkflow(app modular.Application, workflowConfig interface{}) error

ConfigureWorkflow sets up the workflow from configuration

func (*StateMachineWorkflowHandler) ExecuteWorkflow

func (h *StateMachineWorkflowHandler) ExecuteWorkflow(ctx context.Context, workflowType string, action string, data map[string]interface{}) (map[string]interface{}, error)

ExecuteWorkflow executes a workflow with the given action and input data

func (*StateMachineWorkflowHandler) Name

Name returns the name of this handler

type TestJob

type TestJob struct {
	ExecuteFn func(ctx context.Context) error
}

TestJob is a simple job implementation for testing

func NewTestJob

func NewTestJob(fn func(ctx context.Context) error) *TestJob

NewTestJob creates a new test job

func (*TestJob) Execute

func (j *TestJob) Execute(ctx context.Context) error

Execute executes the job

type TestServiceRegistry

type TestServiceRegistry struct {
	// contains filtered or unexported fields
}

TestServiceRegistry provides a simple service registry for testing

func NewTestServiceRegistry

func NewTestServiceRegistry() *TestServiceRegistry

NewTestServiceRegistry creates a new test service registry

func (*TestServiceRegistry) ConfigProvider

func (t *TestServiceRegistry) ConfigProvider() modular.ConfigProvider

ConfigProvider returns the config provider

func (*TestServiceRegistry) ConfigSections

func (t *TestServiceRegistry) ConfigSections() map[string]modular.ConfigProvider

ConfigSections returns configuration sections

func (*TestServiceRegistry) GetConfigSection

func (t *TestServiceRegistry) GetConfigSection(section string) (modular.ConfigProvider, error)

GetConfigSection returns a config section

func (*TestServiceRegistry) GetService

func (t *TestServiceRegistry) GetService(name string, dest interface{}) error

GetService implements service retrieval for testing

func (*TestServiceRegistry) Init

func (t *TestServiceRegistry) Init() error

Init initializes the test registry

func (*TestServiceRegistry) IsVerboseConfig

func (t *TestServiceRegistry) IsVerboseConfig() bool

IsVerboseConfig returns whether verbose config debugging is enabled

func (*TestServiceRegistry) Logger

func (t *TestServiceRegistry) Logger() modular.Logger

Logger returns a logger

func (*TestServiceRegistry) RegisterConfigSection

func (t *TestServiceRegistry) RegisterConfigSection(name string, config modular.ConfigProvider)

RegisterConfigSection registers a config section

func (*TestServiceRegistry) RegisterModule

func (t *TestServiceRegistry) RegisterModule(module modular.Module)

RegisterModule registers a module in the test registry

func (*TestServiceRegistry) RegisterService

func (t *TestServiceRegistry) RegisterService(name string, service interface{}) error

RegisterService implements service registration for testing

func (*TestServiceRegistry) Run

func (t *TestServiceRegistry) Run() error

Run simulates application run

func (*TestServiceRegistry) SetLogger

func (t *TestServiceRegistry) SetLogger(logger modular.Logger)

SetLogger sets the application's logger

func (*TestServiceRegistry) SetMockConfig

func (t *TestServiceRegistry) SetMockConfig(config modular.ConfigProvider)

SetMockConfig sets a custom config provider

func (*TestServiceRegistry) SetMockLogger

func (t *TestServiceRegistry) SetMockLogger(logger modular.Logger)

SetMockLogger sets a custom logger

func (*TestServiceRegistry) SetVerboseConfig

func (t *TestServiceRegistry) SetVerboseConfig(enabled bool)

SetVerboseConfig sets verbose config debugging (no-op for tests)

func (*TestServiceRegistry) Start

func (t *TestServiceRegistry) Start() error

Start simulates application start

func (*TestServiceRegistry) Stop

func (t *TestServiceRegistry) Stop() error

Stop simulates application stop

func (*TestServiceRegistry) SvcRegistry

func (t *TestServiceRegistry) SvcRegistry() modular.ServiceRegistry

SvcRegistry returns the services map as modular.ServiceRegistry

type TopicHandlerConfig

type TopicHandlerConfig struct {
	Topic   string                 `json:"topic" yaml:"topic"`
	Handler string                 `json:"handler" yaml:"handler"`
	Config  map[string]interface{} `json:"config,omitempty" yaml:"config,omitempty"`
}

TopicHandlerConfig represents a topic handler configuration in messaging workflow

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL