Class: Ahoy::Stores::NsqStore

Inherits:
LogStore show all
Defined in:
lib/ahoy/stores/nsq_store.rb

Instance Method Summary collapse

Methods inherited from LogStore

#track_event, #track_visit

Methods inherited from BaseStore

#authenticate, #exclude?, #generate_id, #initialize, #report_exception, #track_event, #track_visit, #user, #visit

Constructor Details

This class inherits a constructor from Ahoy::Stores::BaseStore

Instance Method Details

#clientObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/ahoy/stores/nsq_store.rb', line 12

def client
  @client ||= begin
    require "nsq"
    client = Nsq::Producer.new(
      nsqd: ENV["NSQ_URL"] || "127.0.0.1:4150"
    )
    at_exit { client.terminate }
    client
  end
end

#events_topicObject



31
32
33
# File 'lib/ahoy/stores/nsq_store.rb', line 31

def events_topic
  "ahoy_events"
end

#log_event(data) ⇒ Object



8
9
10
# File 'lib/ahoy/stores/nsq_store.rb', line 8

def log_event(data)
  post(events_topic, data)
end

#log_visit(data) ⇒ Object



4
5
6
# File 'lib/ahoy/stores/nsq_store.rb', line 4

def log_visit(data)
  post(visits_topic, data)
end

#post(topic, data) ⇒ Object



23
24
25
# File 'lib/ahoy/stores/nsq_store.rb', line 23

def post(topic, data)
  client.write_to_topic(topic, data.to_json)
end

#visits_topicObject



27
28
29
# File 'lib/ahoy/stores/nsq_store.rb', line 27

def visits_topic
  "ahoy_visits"
end