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.6.3 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.2 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.1 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.6.0 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.5.1 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.5.0 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.32 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.31 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.30 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.29 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.28 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.27 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.26 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.25 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.24 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.23 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.22 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.21 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.20 framework_components/logging_bot/logging_bot.rb
nutella_framework-0.4.19 framework_components/logging_bot/logging_bot.rb