Class: Tasker::Events::SubscriptionLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/tasker/events/subscription_loader.rb

Overview

SubscriptionLoader loads event subscriptions from YAML configuration files

This class enables developers to configure event subscriptions declaratively using YAML files in config/tasker/subscriptions/

Example YAML structure: subscriptions: sentry_integration: class: 'SentrySubscriber' events: - 'task.failed' - 'step.failed' config: dsn: 'https://...' environment: 'production'

Class Method Summary collapse

Class Method Details

.load_allHash

Load all subscription configurations from YAML files

Returns:

  • (Hash)

    Loaded subscription configurations



28
29
30
# File 'lib/tasker/events/subscription_loader.rb', line 28

def load_all
  @load_all ||= load_subscription_files
end

.load_subscribersArray<BaseSubscriber>

Load and instantiate all configured subscribers

Returns:

  • (Array<BaseSubscriber>)

    Array of instantiated subscribers



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tasker/events/subscription_loader.rb', line 35

def load_subscribers
  subscribers = []

  load_all.each do |name, config|
    subscriber = instantiate_subscriber(name, config)
    subscribers << subscriber if subscriber
  rescue StandardError => e
    Rails.logger.warn "Failed to load subscriber #{name}: #{e.message}"
  end

  subscribers
end

.register_all_subscribersvoid

This method returns an undefined value.

Register all loaded subscribers with the event system



51
52
53
54
55
56
# File 'lib/tasker/events/subscription_loader.rb', line 51

def register_all_subscribers
  load_subscribers.each do |subscriber|
    Rails.logger.info "Registering subscriber: #{subscriber.class.name}"
    # Subscribers auto-register themselves when instantiated
  end
end

.reload!Hash

Reload subscription configurations (useful for development)

Returns:

  • (Hash)

    Reloaded subscription configurations



61
62
63
64
# File 'lib/tasker/events/subscription_loader.rb', line 61

def reload!
  @loaded_subscriptions = nil
  load_all
end