Sha256: 6ca0e1d17a30be8adda7a94fdbd78415e8d13e2a0a01e1211c61ad63abb5e98c

Contents?: true

Size: 1.71 KB

Versions: 51

Compression:

Stored size: 1.71 KB

Contents

# Logger bot
# ----------
#
# This bot is in charge of recording all the messages that are sent by
# all components in all runs. It records all info sent to channels:
# - `/nutella/logging`
# - `/nutella/apps/<app_id>/logging`
# - `/nutella/apps/<app_id>/runs/<run_id>/logging`
# All logs are appended to a MongoDB collection called `logs`, inside the
# `nutella` database.
#
# -----------------------------------------------------------------------------

require_relative '../../lib/config/runlist'
require_relative '../../lib/config/config'
require_relative '../../nutella_lib/framework_core'

require_relative 'utils'

# Initialize this bot as framework component
nutella.f.init(Nutella.config['broker'], 'example_framework_bot')

# Get a mongo persisted collection
logs = nutella.f.persist.get_mongo_collection_store 'logs'
dump = nutella.f.persist.get_mongo_collection_store 'dump'


# Listen for run-level log messages
nutella.f.net.subscribe_to_all_runs('logging', lambda do |payload, app_id, run_id, from|
  logs.push assemble_log(payload, from)
end)

# Listen for app-level log messages
nutella.f.net.subscribe_to_all_apps('logging', lambda do |payload, app_id, from|
  logs.push assemble_log(payload, from)
end)

# Listen for framework-level log messages
nutella.f.net.subscribe('logging', lambda do |payload, from|
  logs.push assemble_log(payload, from)
end)


# Listen for low-level messages that are archived in the 'dump' collection
bare_mqtt_client = SimpleMQTTClient.new Nutella.config['broker']
bare_mqtt_client.subscribe('/nutella/#', lambda do |message, channel|
  begin
    dump.push assemble_dump(JSON.parse(message), channel)
  rescue
    # Ignore non JSON
  end
end)

# Listen and process messages as they come
nutella.f.net.listen

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
nutella_framework-0.7.2 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.7.1 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.7.0 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.21 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.20 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.19 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.18 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.17 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.16 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.15 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.13 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.12 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.11 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.10 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.9 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.8 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.7 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.6 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.5 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.4 framework_components/logging_bot/logging_bot.rb