Class: OpticsAgent::Agent
- Inherits:
-
Object
- Object
- OpticsAgent::Agent
show all
- Includes:
- Reporting, Singleton
- Defined in:
- lib/optics-agent/agent.rb
Overview
XXX: this is a class but acts as a singleton right now. Need to figure out how to pass the agent into the middleware
(for instance we could dynamically generate a middleware class,
or ask the user to pass the agent as an option) to avoid it
Constant Summary
Constants included
from Reporting
Reporting::OPTICS_URL
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Reporting
#add_latency, #client_info, #duration_nanos, #generate_report_header, #generate_timestamp, #send_message
Constructor Details
#initialize ⇒ Agent
Returns a new instance of Agent.
19
20
21
22
|
# File 'lib/optics-agent/agent.rb', line 19
def initialize
@query_queue = []
@semaphone = Mutex.new
end
|
Instance Attribute Details
#schema ⇒ Object
Returns the value of attribute schema.
17
18
19
|
# File 'lib/optics-agent/agent.rb', line 17
def schema
@schema
end
|
Instance Method Details
#add_query(query, rack_env, start_time, end_time) ⇒ Object
37
38
39
40
41
|
# File 'lib/optics-agent/agent.rb', line 37
def add_query(query, rack_env, start_time, end_time)
@semaphone.synchronize {
@query_queue << [query, rack_env, start_time, end_time]
}
end
|
#clear_query_queue ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/optics-agent/agent.rb', line 43
def clear_query_queue
@semaphone.synchronize {
queue = @query_queue
@query_queue = []
queue
}
end
|
#graphql_middleware ⇒ Object
#instrument_schema(schema) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/optics-agent/agent.rb', line 24
def instrument_schema(schema)
@schema = schema
schema.middleware << graphql_middleware
puts 'scheduling schema job'
SchemaJob.perform_in(10, self)
schedule_report
end
|
#rack_middleware ⇒ Object
#schedule_report ⇒ Object
33
34
35
|
# File 'lib/optics-agent/agent.rb', line 33
def schedule_report
ReportJob.perform_in(60, self)
end
|