Module: SpeakingApps

Defined in:
lib/speaking_apps.rb,
lib/speaking_apps/config.rb,
lib/speaking_apps/daemon/remote.rb,
lib/speaking_apps/message_queue.rb,
lib/speaking_apps/daemon/queue_service.rb

Overview

This is the place to read about the methods that will help you sending Messages/Logs to the SpeakingApps API Service.

Please make sure you set the required SpeakingApps::Config values.

Defined Under Namespace

Modules: Daemon Classes: Config, MessageQueue

Class Method Summary collapse

Class Method Details

.ensure_existence_of_service_daemonObject

:nodoc:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/speaking_apps.rb', line 50

def ensure_existence_of_service_daemon #:nodoc:
  begin
    Timeout::timeout(10) do
      unless message_queue.ping
        bin_path = File.expand_path(File.join(File.dirname(__FILE__), '/../bin/speaking-apps'))
        Kernel.system("#{bin_path} start")
      end
      sleep 1
    end
    send_to_app "=> SpeakingApps: API service ready."
  rescue
    send_to_app "=> SpeakingApps: API service is not available!"
  end
end

.init(environment = nil) ⇒ Object

:nodoc:



13
14
15
16
17
18
# File 'lib/speaking_apps.rb', line 13

def init(environment = nil) #:nodoc:
  unless class_variable_defined?(:@@_message_queue)
    @@_message_queue = SpeakingApps::MessageQueue.new(environment)
    ensure_existence_of_service_daemon# if @@_message_queue.environment_valid?
  end      
end

.log(message, *tags) ⇒ Object

Send a Messages. You can optionally assign Tags.

  • SpeakingApps.log('hello World')

  • SpeakingApps.log('hello World', 'tag1', 'tag2', 'tagx')



24
25
26
27
28
29
30
31
# File 'lib/speaking_apps.rb', line 24

def log(message, *tags)
  begin
    message_queue.add(message, tags)
    true
  rescue
    false
  end
end

.log_with_tags(*tags, &block) ⇒ Object

Send a Messages with tags.

  • SpeakingApps.log_with_tags('tag1', 'tag2') { 'Hello World' }



36
37
38
39
40
41
42
43
44
# File 'lib/speaking_apps.rb', line 36

def log_with_tags(*tags, &block)
  begin
    message = yield
    message_queue.add(message, tags)
    true
  rescue
    false
  end
end

.message_queueObject

:nodoc:



46
47
48
# File 'lib/speaking_apps.rb', line 46

def message_queue #:nodoc:
  @@_message_queue
end

.send_to_app(message) ⇒ Object



65
66
67
# File 'lib/speaking_apps.rb', line 65

def send_to_app(message)
  $stdout.puts message
end