-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.py
77 lines (60 loc) · 2.35 KB
/
checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
from sqs import (make_SQS_connection, get_queue, queue_size, )
from cloudwatch import (make_CW_connection, update_metric, )
from threading import Timer
# Define AWS credentials
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
REGION = 'us-west-2'
# Set queue name variables
FULL_COMPOSITE_QUEUE = 'snapsat_composite_queue'
PREVIEW_COMPOSITE_QUEUE = 'snapsat_preview_queue'
# Set metric name variables
FULL_COMPOSITE_METRIC = 'number_jobs_full_queue'
PREVIEW_COMPOSITE_METRIC = 'number_jobs_preview_queue'
# Set metric namespace
NAMESPACE = 'Snapsat'
# Set size check intervals
FULL_INTERVAL = 10
PREVIEW_INTERVAL = 10
# Create SQS connction
SQSconn = make_SQS_connection(REGION,
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY)
# Create CW connection
CWconn = make_CW_connection(REGION,
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY)
# Monitor size of queue
def monitor_queue(SQSconn, CWconn, queue_name, metric_name):
queue = get_queue(SQSconn, queue_name)
size = queue_size(queue)
update_metric(CWconn, NAMESPACE, metric_name, size)
# Create full queue size check timer funciton
def full_queue_timer(SQSconn, CWconn, queue_name, metric_name, interval):
monitor_queue(SQSconn, CWconn, queue_name, metric_name)
return Timer(interval,
full_queue_timer,
args=[SQSconn, CWconn, queue_name, metric_name, interval]
).start()
# Create preview queue size check timer funciton
def preview_queue_timer(SQSconn, CWconn, queue_name, metric_name, interval):
monitor_queue(SQSconn, CWconn, queue_name, metric_name)
return Timer(interval,
full_queue_timer,
args=[SQSconn, CWconn, queue_name, metric_name, interval]
).start()
# Check queue sizes every 20 seconds
def main():
full_queue_timer(SQSconn,
CWconn,
FULL_COMPOSITE_QUEUE,
FULL_COMPOSITE_METRIC,
FULL_INTERVAL)
preview_queue_timer(SQSconn,
CWconn,
PREVIEW_COMPOSITE_QUEUE,
PREVIEW_COMPOSITE_METRIC,
PREVIEW_INTERVAL)
if __name__ == '__main__':
main()