mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-10 02:40:56 +08:00
Fixes #7
* added a synchronous cluster simulation * added a test for the sync function * moved signing into its own module * refactored imports to solve circular import problems stemming from the task module pretending to be a cluster * added documentation for the new sync option
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
try:
|
||||
import cPickle as pickle
|
||||
except ImportError:
|
||||
import pickle
|
||||
|
||||
from django.core import signing
|
||||
from django_q.conf import Conf
|
||||
|
||||
BadSignature = signing.BadSignature
|
||||
|
||||
class SignedPackage(object):
|
||||
"""
|
||||
Wraps Django's signing module with custom Pickle serializer
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def dumps(obj, compressed=Conf.COMPRESSED):
|
||||
return signing.dumps(obj,
|
||||
key=Conf.SECRET_KEY,
|
||||
salt='django_q.q',
|
||||
compress=compressed,
|
||||
serializer=PickleSerializer)
|
||||
|
||||
@staticmethod
|
||||
def loads(obj):
|
||||
return signing.loads(obj,
|
||||
key=Conf.SECRET_KEY,
|
||||
salt='django_q.q',
|
||||
serializer=PickleSerializer)
|
||||
|
||||
|
||||
class PickleSerializer(object):
|
||||
"""
|
||||
Simple wrapper around Pickle for signing.dumps and
|
||||
signing.loads.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def dumps(obj):
|
||||
return pickle.dumps(obj)
|
||||
|
||||
@staticmethod
|
||||
def loads(data):
|
||||
return pickle.loads(data)
|
||||
Reference in New Issue
Block a user