func()

in internal/app/adapters/inbound/file/file_inbound.go [59:92]


func (f *FileInboundEndpoint) Start(ctx context.Context, mediator ports.InboundMessageMediator) error {
	// Check if context is already canceled before proceeding
	select {
	case <-ctx.Done():
		// Context already canceled, don't decrement WaitGroup
		return ctx.Err()
	default:
		// Context still valid, proceed with normal operation
	}

	if err := f.validateConfig(); err != nil {
		slog.Error("invalid configuration", "error", err)
		return fmt.Errorf("configuration validation failed: %w", err)
	}

	f.mediator = mediator
	vfsFactory := &VFSProtocolHandlerFactory{}
	handler, err := vfsFactory.CreateHandler(f.config)
	if err != nil {
		slog.Error("failed to create protocol handler", "error", err)
		return fmt.Errorf("failed to create protocol handler: %w", err)
	}
	f.protocolHandler = handler

	slog.Info("starting file inbound endpoint")

	// Start polling
	err = f.poll(ctx)

	// When context is cancelled, wait for all processing to complete
	slog.Info("waiting for in-progress file operations to complete")

	return err
}