-
Notifications
You must be signed in to change notification settings - Fork 5
/
sqs.py
153 lines (106 loc) · 3.63 KB
/
sqs.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from boto.sqs import connect_to_region
from sms import SMS
import setting
import ujson as json
import t
AWSSQS = connect_to_region(setting.AWSREGION,
aws_access_key_id=setting.AWSID,
aws_secret_access_key=setting.AWSKEY)
AWSSQSLIST = []
def SQSLIST(f):
AWSSQSLIST.append(f.__name__)
return f
def add(QUEUE_NAME, DATA):
isinstance(DATA, list)
q = AWSSQS.get_queue(QUEUE_NAME)
for i in DATA:
q.write(q.new_message(json.dumps(i)))
def doing(QUEUE_NAME, DOING):
q = AWSSQS.get_queue(QUEUE_NAME)
result = []
for i in xrange(setting.FEEDS):
read_m = q.read()
if read_m:
result.append(DOING(json.loads(read_m.get_body())))
q.delete_message(read_m)
else:
result.append(False)
return result
def clear(QUEUE_NAME):
q = AWSSQS.get_queue(QUEUE_NAME)
q.clear()
def keepgoing(QUEUE_NAME, DOING):
sleep_times = 0
q = AWSSQS.get_queue(QUEUE_NAME)
while 1:
rest = q.count()
print sleep_times
if rest:
d = doing(QUEUE_NAME, DOING)
print d
if any(d):
sleep_times = 0
else:
sleep_times += 1
else:
sleep_times += 1
if sleep_times >= setting.SLEEP_TIMES:
break
@SQSLIST
def sqs_send_first():
t.template = t.env.get_template('./coscup_first.htm')
keepgoing(setting.QUEUE_NAME_SENDFIRST, t.send_first)
@SQSLIST
def sqs_send_register():
t.template = t.env.get_template('./coscup_register.htm')
keepgoing(setting.QUEUE_NAME_REGISTER, t.send_register)
@SQSLIST
def sqs_send_speakerparty():
t.template = t.env.get_template('./coscup_speakerparty.htm')
keepgoing(setting.QUEUE_NAME_SENDSPEAKERPARTY, t.send_speakerparty)
@SQSLIST
def sqs_send_attendee_reminder():
t.template = t.env.get_template('./coscup_attendee.htm')
keepgoing(setting.QUEUE_NAME_SENDATTENDEEREMINDER, t.send_attendee_reminder)
@SQSLIST
def sqs_send_survey():
t.template = t.env.get_template('./coscup_survey.htm')
keepgoing(setting.QUEUE_NAME_SENDSURVEY, t.send_survey)
@SQSLIST
def sqs_send_staff_reminder():
t.template = t.env.get_template('./coscup_staff.htm')
keepgoing(setting.QUEUE_NAME_SENDSTAFFREMINDER, t.send_staff_reminder)
@SQSLIST
def sqs_send_paper():
keepgoing(setting.QUEUE_NAME_SENDPAPER, t.send_paper)
@SQSLIST
def sqs_send_welcome():
t.template = t.env.get_template('./coscup_welcome.htm')
keepgoing(setting.QUEUE_NAME_SENDWELCOME, t.send_welcome)
@SQSLIST
def sqs_send_leadervipcode():
t.template = t.env.get_template('./coscup_leader_vip.htm')
keepgoing(setting.QUEUE_NAME_SENDLEADERVIPCODE, t.send_leadervipcode)
@SQSLIST
def sqs_send_oscvipcode():
t.template = t.env.get_template('./coscup_osc.htm')
keepgoing(setting.QUEUE_NAME_SENDOSCVIPCODE, t.send_leadervipcode)
@SQSLIST
def sqs_send_personalsponsor():
t.template = t.env.get_template('./coscup_personal_sponsor.htm')
keepgoing(setting.QUEUE_NAME_SENDPERSONALSPONSOR, t.send_personal_sponsor)
@SQSLIST
def sqs_send_personalsponsorresend():
t.template = t.env.get_template('./coscup_personal_sponsor_resend.htm')
keepgoing(setting.QUEUE_NAME_SENDPERSONALSPONSORRESEND,
t.send_personal_sponsor)
@SQSLIST
def sqs_sms_leader():
doing_sms = SMS().send
keepgoing(setting.QUEUE_NAME_SMSLEADER, doing_sms)
if __name__ == '__main__':
#print clear(setting.QUEUE_NAME_SMSLEADER)
#add(setting.QUEUE_NAME, [str(datetime.now()), str(datetime.now())])
print 'IN SQS.'