~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to src/mailman/model/pending.py

  • Committer: Barry Warsaw
  • Date: 2012-03-26 12:04:00 UTC
  • Revision ID: barry@list.org-20120326120400-jfezy6cg60ygod7k
Architecture
------------
 * Internally, all datetimes are kept in the UTC timezone, however because of
   LP: #280708, they are stored in the database in naive format.
 * `received_time` is now added to the message metadata by the LMTP runner
   instead of by `Switchboard.enqueue()`.  This latter no longer depends on
   `received_time` in the metadata.
 * The `ArchiveRunner` no longer acquires a lock before it calls the
   individual archiver implementations, since not all of them need a lock.  If
   they do, the implementations must acquire said lock themselves.

Configuration
-------------
 * New configuration variables `clobber_date` and `clobber_skew` supported in
   every `[archiver.<name>]` section.  These are used to determine under what
   circumstances a message destined for a specific archiver should have its
   `Date:` header clobbered.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import time
30
30
import random
31
31
import hashlib
32
 
import datetime
33
32
 
34
33
from lazr.config import as_timedelta
35
34
from storm.locals import DateTime, Int, RawStr, ReferenceSet, Unicode
40
39
from mailman.database.model import Model
41
40
from mailman.interfaces.pending import (
42
41
    IPendable, IPended, IPendedKeyValue, IPendings)
 
42
from mailman.utilities.datetime import now
43
43
from mailman.utilities.modules import call_name
44
44
 
45
45
 
98
98
        # does the hash calculation.  The integral parts of the time values
99
99
        # are discarded because they're the most predictable bits.
100
100
        for attempts in range(3):
101
 
            now = time.time()
102
 
            x = random.random() + now % 1.0 + time.clock() % 1.0
 
101
            right_now = time.time()
 
102
            x = random.random() + right_now % 1.0 + time.clock() % 1.0
103
103
            # Use sha1 because it produces shorter strings.
104
104
            token = hashlib.sha1(repr(x)).hexdigest()
105
105
            # In practice, we'll never get a duplicate, but we'll be anal
111
111
        # Create the record, and then the individual key/value pairs.
112
112
        pending = Pended(
113
113
            token=token,
114
 
            expiration_date=datetime.datetime.now() + lifetime)
 
114
            expiration_date=now() + lifetime)
115
115
        for key, value in pendable.items():
116
116
            if isinstance(key, str):
117
117
                key = unicode(key, 'utf-8')
160
160
 
161
161
    def evict(self):
162
162
        store = config.db.store
163
 
        now = datetime.datetime.now()
 
163
        right_now = now()
164
164
        for pending in store.find(Pended):
165
 
            if pending.expiration_date < now:
 
165
            if pending.expiration_date < right_now:
166
166
                # Find all PendedKeyValue entries that are associated with the
167
167
                # pending object's ID.
168
168
                q = store.find(PendedKeyValue,