Skip to content

Commit 0c8a71a

Browse files
committed
rename readme ext to rst
1 parent 00b8bd1 commit 0c8a71a

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include readme.txt
1+
include README.rst

mongoqueue/mongoqueue.py

+31-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121

2222
DEFAULT_INSERT = {
23-
"priority": 0,
2423
"attempts": 0,
2524
"locked_by": None,
2625
"locked_at": None,
@@ -70,10 +69,18 @@ def repair(self):
7069
"$inc": {"attempts": 1}}
7170
)
7271

73-
def put(self, payload):
72+
def drop_max_attempts(self):
73+
"""
74+
"""
75+
self.collection.find_and_modify(
76+
{"attempts": {"$gte": self.max_attempts}},
77+
remove=True)
78+
79+
def put(self, payload, priority=0):
7480
"""Place a job into the queue
7581
"""
7682
job = dict(DEFAULT_INSERT)
83+
job['priority'] = priority
7784
job['payload'] = payload
7885
return self.collection.insert(job)
7986

@@ -82,8 +89,7 @@ def next(self):
8289
query={"locked_by": None,
8390
"locked_at": None,
8491
"attempts": {"$lt": self.max_attempts}},
85-
update={"$set": {"attempts": 1,
86-
"locked_by": self.consumer_id,
92+
update={"$set": {"locked_by": self.consumer_id,
8793
"locked_at": datetime.now()}},
8894
sort=[('priority', pymongo.DESCENDING)],
8995
new=1,
@@ -128,10 +134,6 @@ def __init__(self, queue, data):
128134
self._queue = queue
129135
self._data = data
130136

131-
@property
132-
def data(self):
133-
return self._data
134-
135137
@property
136138
def payload(self):
137139
return self._data['payload']
@@ -140,6 +142,26 @@ def payload(self):
140142
def job_id(self):
141143
return self._data["_id"]
142144

145+
@property
146+
def priority(self):
147+
return self._data["priority"]
148+
149+
@property
150+
def attempts(self):
151+
return self._data["attempts"]
152+
153+
@property
154+
def locked_by(self):
155+
return self._data["locked_by"]
156+
157+
@property
158+
def locked_at(self):
159+
return self._data["locked_at"]
160+
161+
@property
162+
def last_error(self):
163+
return self._data["last_error"]
164+
143165
## Job Control
144166

145167
def complete(self):
@@ -176,7 +198,7 @@ def release(self):
176198
## Context Manager support
177199

178200
def __enter__(self):
179-
return self.data
201+
return self._data
180202

181203
def __exit__(self, type, value, tb):
182204
if (type, value, tb) == (None, None, None):

0 commit comments

Comments
 (0)