dsmq 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dsmq/dsmq.py
CHANGED
@@ -10,6 +10,8 @@ DEFAULT_PORT = 30008
|
|
10
10
|
|
11
11
|
N_RETRIES = 5
|
12
12
|
FIRST_RETRY = 0.01 # seconds
|
13
|
+
TIME_TO_LIVE = 60 # seconds
|
14
|
+
TIME_TO_LIVE = 5 # seconds
|
13
15
|
|
14
16
|
|
15
17
|
def start_server(host=DEFAULT_HOST, port=DEFAULT_PORT):
|
@@ -79,8 +81,9 @@ def _handle_client_connection(socket_conn):
|
|
79
81
|
sqlite_conn = sqlite3.connect("file:mem1?mode=memory&cache=shared")
|
80
82
|
cursor = sqlite_conn.cursor()
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
+
client_creation_time = time.time()
|
85
|
+
last_read_times = {}
|
86
|
+
time_of_last_purge = time.time()
|
84
87
|
|
85
88
|
while True:
|
86
89
|
data = socket_conn.recv(1024)
|
@@ -123,10 +126,10 @@ VALUES (:timestamp, :topic, :message)
|
|
123
126
|
|
124
127
|
elif msg["action"] == "get":
|
125
128
|
try:
|
126
|
-
last_read_time =
|
129
|
+
last_read_time = last_read_times[topic]
|
127
130
|
except KeyError:
|
128
|
-
|
129
|
-
last_read_time =
|
131
|
+
last_read_times[topic] = client_creation_time
|
132
|
+
last_read_time = last_read_times[topic]
|
130
133
|
msg["last_read_time"] = last_read_time
|
131
134
|
|
132
135
|
# This block allows for multiple retries if the database
|
@@ -159,7 +162,7 @@ AND timestamp = a.min_time
|
|
159
162
|
result = cursor.fetchall()[0]
|
160
163
|
message = result[0]
|
161
164
|
timestamp = result[1]
|
162
|
-
|
165
|
+
last_read_times[topic] = timestamp
|
163
166
|
except IndexError:
|
164
167
|
# Handle the case where no results are returned
|
165
168
|
message = ""
|
@@ -169,6 +172,20 @@ AND timestamp = a.min_time
|
|
169
172
|
else:
|
170
173
|
print("Action must either be 'put' or 'get'")
|
171
174
|
|
175
|
+
# Periodically clean out messages from the queue that are
|
176
|
+
# past their sell buy date.
|
177
|
+
# This operation is pretty fast. I clock it at 12 us on my machine.
|
178
|
+
if time.time() - time_of_last_purge > TIME_TO_LIVE:
|
179
|
+
cursor.execute(
|
180
|
+
"""
|
181
|
+
DELETE FROM messages
|
182
|
+
WHERE timestamp < :time_threshold
|
183
|
+
""",
|
184
|
+
{"time_threshold": time_of_last_purge}
|
185
|
+
)
|
186
|
+
sqlite_conn.commit()
|
187
|
+
time_of_last_purge = time.time()
|
188
|
+
|
172
189
|
sqlite_conn.close()
|
173
190
|
|
174
191
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
dsmq/__init__.py,sha256=YCgbnQAk8YbtHRyMcU0v2O7RdRhPhlT-vS_q40a7Q6g,50
|
2
2
|
dsmq/demo_linux.py,sha256=7yLglGmirDLuuyMxppYSK-dfx2Fg2Q0dIWB4cl2yV1c,622
|
3
|
-
dsmq/dsmq.py,sha256=
|
3
|
+
dsmq/dsmq.py,sha256=dKYtGkg8Kwll2sCytCqSI5klFs2cwm2pyXAkyQk4RdU,6206
|
4
4
|
dsmq/example_get_client.py,sha256=chFfB2949PBENmgdUc3ASrATq1m4wvHGBzEnOC-o_Xs,296
|
5
5
|
dsmq/example_put_client.py,sha256=mUKCRhmUieMZEpHLFWFvzeKB6IR7A8l4tWN8TvPzdKU,348
|
6
6
|
dsmq/example_server.py,sha256=kkXOPaaTzVxf9_iIM76zU9pZhkPna_1vcGWkPrhCjus,61
|
7
|
-
dsmq-0.
|
8
|
-
dsmq-0.
|
9
|
-
dsmq-0.
|
10
|
-
dsmq-0.
|
7
|
+
dsmq-0.5.0.dist-info/METADATA,sha256=EQISO0WcVsb7smXIie-ZP7pIO1itY8FZfjGw3DPuZDM,3878
|
8
|
+
dsmq-0.5.0.dist-info/WHEEL,sha256=3U_NnUcV_1B1kPkYaPzN-irRckL5VW_lytn0ytO_kRY,87
|
9
|
+
dsmq-0.5.0.dist-info/licenses/LICENSE,sha256=3Yu1mAp5VsKmnDtzkiOY7BdmrLeNwwZ3t6iWaLnlL0Y,1071
|
10
|
+
dsmq-0.5.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|