Class: Driftwood::Plugin::Logger
- Inherits:
-
Driftwood::Plugin
- Object
- Driftwood::Plugin
- Driftwood::Plugin::Logger
- Defined in:
- lib/driftwood/plugin/logger.rb
Instance Attribute Summary
Attributes inherited from Driftwood::Plugin
Instance Method Summary collapse
-
#initialize(config = nil, slack = nil, bigquery = nil) ⇒ Logger
constructor
A new instance of Logger.
- #sync_channels ⇒ Object
- #sync_messages ⇒ Object
- #sync_users ⇒ Object
Constructor Details
#initialize(config = nil, slack = nil, bigquery = nil) ⇒ Logger
Returns a new instance of Logger.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/driftwood/plugin/logger.rb', line 3 def initialize(config=nil, slack=nil, bigquery=nil) super(config, slack, bigquery) @about = 'Logs all public messages to BigQuery.' # logging handler @slack.register_handler('message') do |team_id, event_data| next unless event_data['channel_type'] == 'channel' $logger.debug "Logged message for #{team_id}: #{event_data['text']}" @bigquery.(@slack.(team_id, event_data)) end # register new users @slack.register_handler('team_join') do |team_id, event_data| user = @slack.normalize_user(event_data['user']) $logger.info "Registered new user: #{user['name']} (#{user['real_name']})" @bigquery.insert_user(user) end # Do this in a thread so it doesn't block initialization # These methods may take a long time to complete Thread.new do begin $logger.info "Starting data synchronization..." sync_channels sync_users rescue => e $logger.error e. $logger.debug e.backtrace.join("\n") end loop do sleep 86400 # Once a day; 60 * 60 * 24 begin $logger.info "Purging deleted users..." @bigquery.purge_deleted_users rescue => e $logger.error e. $logger.debug e.backtrace.join("\n") end end end end |
Instance Method Details
#sync_channels ⇒ Object
47 48 49 50 51 52 |
# File 'lib/driftwood/plugin/logger.rb', line 47 def sync_channels @slack.all_channels.each do |channel| @bigquery.insert_channel(channel) end $logger.info "All channels synced." end |
#sync_messages ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/driftwood/plugin/logger.rb', line 62 def starting_from = @bigquery. @slack.(starting_from).each do || @bigquery.() end $logger.info "All messages synced." end |
#sync_users ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/driftwood/plugin/logger.rb', line 54 def sync_users @slack.all_users.each do |user| @bigquery.insert_user(user) end @bigquery.reconcile_user_creations $logger.info "All users synced." end |