Module: IRFSDash

Defined in:
lib/irfsdash.rb,
lib/irfsdash/version.rb

Constant Summary collapse

VERSION =
"0.1.5"

Class Method Summary collapse

Class Method Details

.activity(opts = {}) ⇒ Object

Publish to the activity stream Minimum: :source, :content

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
# File 'lib/irfsdash.rb', line 33

def self.activity(opts={})
  msg = opts.merge!(@defaults)
  raise ArgumentError, "No source specified" unless msg[:source]
  raise ArgumentError, "No content specified" unless msg[:content]
  raise ArgumentError, "No type specified" unless msg[:type]
  self.amqp.exchange("irfs-dashboard.activity", type: :fanout).publish(JSON.dump(msg))
end

.amqpObject

Returns an AMQP channel



15
16
17
18
19
20
# File 'lib/irfsdash.rb', line 15

def self.amqp
  return @b if @b
  @b = Bunny.new(host: self.amqp_host)
  @b.start
  return @b
end

.amqp_host(host = '10.10.12.156') ⇒ Object

Set the AMQP host



11
12
13
# File 'lib/irfsdash.rb', line 11

def self.amqp_host(host='10.10.12.156')
  @amqp_host ||= host
end

.decrement(*args) ⇒ Object

Decrement a counter in statsd. Arguments: Counter name to decrement, optional sample rate



73
74
75
# File 'lib/irfsdash.rb', line 73

def self.decrement(*args)
  self.statsd.decrement(*args)
end

.increment(*args) ⇒ Object

Increment a counter in statsd. Arguments: Counter name to increment, optional sample rate



68
69
70
# File 'lib/irfsdash.rb', line 68

def self.increment(*args)
  self.statsd.increment(*args)
end

.project(opts = {}) ⇒ Object

Publish a project update Minimum: :source, :project, :happy

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
# File 'lib/irfsdash.rb', line 42

def self.project(opts={})
  msg = opts.merge!(@defaults)
  raise ArgumentError, "No source specified" unless msg[:source]
  raise ArgumentError, "No project specified" unless msg[:project]
  raise ArgumentError, "No happy specified" unless msg.keys.include? :happy
  self.amqp.exchange("irfs-dashboard.projects", type: :fanout).publish(JSON.dump(msg))
end

.setup(opts = {}) ⇒ Object

Setup the library’s defaults



28
29
30
# File 'lib/irfsdash.rb', line 28

def self.setup(opts={})
  @defaults = opts
end

.statsdObject



21
22
23
24
25
26
# File 'lib/irfsdash.rb', line 21

def self.statsd
  return @statsd if @statsd
  @statsd = Statsd.new(self.statsd_host, 8125)
  @statsd.namespace('irfsdash')
  return @statsd
end

.statsd_host(host = '10.10.12.156') ⇒ Object

Set the Statsd hostname



7
8
9
# File 'lib/irfsdash.rb', line 7

def self.statsd_host(host='10.10.12.156')
  @statsd_host ||= host
end

.ticker(opts = {}) ⇒ Object

Publish to the ticker Minimum: :source, :content, :ticker_type

Raises:

  • (ArgumentError)


51
52
53
54
55
56
57
# File 'lib/irfsdash.rb', line 51

def self.ticker(opts={})
  msg = opts.merge!(@defaults)
  raise ArgumentError, "No source specified" unless msg[:source]
  raise ArgumentError, "No content specified" unless msg[:content]
  raise ArgumentError, "No ticker type specified" unless msg[:ticker_type]
  self.amqp.exchange("irfs-dashboard.tickers", type: :fanout).publish(JSON.dump(msg))
end

.timing(*args) ⇒ Object

Report a task time in statsd Arguments: Task name, time in milliseconds, optional sample rate



78
79
80
# File 'lib/irfsdash.rb', line 78

def self.timing(*args)
  self.statsd.timing(*args)
end

.widget(opts = {}) ⇒ Object

Publish a widget Minimum: :source, (:content OR :url)

Raises:

  • (ArgumentError)


60
61
62
63
64
65
# File 'lib/irfsdash.rb', line 60

def self.widget(opts={})
  msg = opts.merge!(@defaults)
  raise ArgumentError, "No source specified" unless msg[:source]
  raise ArgumentError, "No content or URL specified" unless msg[:url] or msg[:content]
  self.amqp.exchange("irfs-dashboard.widgets", type: :fanout).publish(JSON.dump(msg))
end