worker.py¶
init()¶
This function sets up various Worker configurations of which name (string passed in to identify worker), server (server instance), input (main_buffer or retry_buffer) and output (retry_buffer) queue are required. Once it has setup it's configurations it will create an instance of AccountTotals and then call reset().
def __init__(self, name, server, input_queue, output_queue, done_sleep=0.05, empty_sleep=1, empty_timeout=1, connection_timeout=5):
self.name = name
self.server = server
self.input_queue = input_queue
"""Description of input queue"""
self.output_queue = output_queue
"""Description of output queue"""
...
self.totals = AccountTotals()
self.reset()
super(Worker, self).__init__()
reset()¶
Simply sets many of the properties that are set after insert_visit() is called to insert data into the database.
loop()¶
This function will try to get an input from the input_queue and then call insert_visit. If the input queue is empty the worker will go to sleep for a certain amount of time before retrying to get a visit. After any visit is inserted or exception raised all Worker variables are reset and the worker sleeps for an amount of time.
insert_visit()¶
Insert visit takes an argument of visit which is passed in from loop which is taken from the input queue.
- check if the visit has expired
- check if account is active & is not in maintanence
- set totals to a new instance of AccountTotals to record local totals for this insert
- check if ip is within a range of blocked ups set by account
- check if visit passes validation has passed
- handle an impression visit
- match the visits referrer to a pattern
-
start a transaction, inserting:
- page
- events
- labels
- redirects
- endpoints
- then perform sync and finally commit the transaction
-
Once that has completed update_totals is called to keep track of the metrics