本文整理汇总了Python中pyres.ResQ类的典型用法代码示例。如果您正苦于以下问题:Python ResQ类的具体用法?Python ResQ怎么用?Python ResQ使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResQ类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: publish
def publish(text, url=None):
'''
Publish status to social networks.
'''
r = ResQ()
r.enqueue(TwitterStatus, text, url)
r.enqueue(VkontakteStatus, text, url)
示例2: Jobs
class Jobs(object):
def __init__(self,host='localhost',port=6379):
HOST = 'localhost:6379'
self.host=host
self.port=port
self.queue='iOSPush'
self.resq = ResQ('%s:%i'%(self.host,self.port))
def push(self,queue,item):
self.resq.push(queue,item)
def pop(self,queue):
return self.resq.pop(queue)
def add(self):
pass
def send(self):
info=self.pop(self.queue) #will get (None, None) if none
info={'badge':1,'msg':'您有新的车票信息','token':'cb86b176ee99ae5f3387c79f1226d234599e91c7bc300e97afb034cc0009e192'}
deviceToken = binascii.unhexlify(info['token'])
message = APNSNotification()
message.token(deviceToken)
message.alert(info['msg'])
message.badge(info['badge'])
message.sound()
wrapper = APNSNotificationWrapper('ck.pem', True)
wrapper.append(message)
wrapper.notify()
示例3: publish
def publish(subject, text):
'''
Publish cumulative post to Livejournal.
'''
r = ResQ()
for target in settings.PUBLISHING_LJ_TARGETS.iterkeys():
r.enqueue(LivejournalPost, target, subject, text)
示例4: all
def all(cls, host="localhost:6379"):
if isinstance(host,string_types):
resq = ResQ(host)
elif isinstance(host, ResQ):
resq = host
return [Worker.find(w,resq) for w in resq.workers() or []]
示例5: perform
def perform(eventid):
print (eventid)
db = sqlitedb()
eventrec = db.getactiveevent()
for event in eventrec:
print event['eventid']
r = ResQ(server="%s:%s" % (resqserver, resqport))
r.enqueue(callQ, event['eventid'])
示例6: test_get_job
def test_get_job(self):
worker = Worker(['basic'])
self.resq.enqueue(Basic,"test1")
job = Job.reserve('basic', self.resq)
worker.working_on(job)
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
assert worker.job() == ResQ.decode(self.redis.get('resque:worker:%s' % name))
assert worker.processing() == ResQ.decode(self.redis.get('resque:worker:%s' % name))
worker.done_working()
w2 = Worker(['basic'])
print w2.job()
assert w2.job() == {}
示例7: retry
def retry(self, payload_class, args):
"""This method provides a way to retry a job after a failure.
If the jobclass defined by the payload containes a ``retry_every``
attribute then pyres will attempt to retry the job until successful
or until timeout defined by ``retry_timeout`` on the payload class.
:param payload_class: the :class:`Job`-like class that needs
to be retried
:type payload_class: :class:`Job`-like
:param args: The args to be passed to the `payload_class.perform`
method when it is retried.
:type args: list
"""
retry_every = getattr(payload_class, 'retry_every', None)
retry_timeout = getattr(payload_class, 'retry_timeout', 0)
if retry_every:
now = ResQ._current_time()
first_attempt = self._payload.get("first_attempt", now)
retry_until = first_attempt + timedelta(seconds=retry_timeout)
retry_at = now + timedelta(seconds=retry_every)
if retry_at < retry_until:
self.resq.enqueue_at(retry_at, payload_class, *args,
**{'first_attempt':first_attempt})
return True
return False
示例8: all
def all(cls, resq, start=0, count=1):
items = resq.redis.lrange('resque:failed', start, count) or []
ret_list = []
for i in items:
failure = ResQ.decode(i)
failure['redis_value'] = b64encode(i)
ret_list.append(failure)
return ret_list
示例9: __init__
def __init__(self, queues, host, max_children=10):
self.queues = queues
self._host = host
self.max_children = max_children
self._shutdown = False
self.children = []
self.resq = ResQ(host)
self.validate_queues()
self.reports = {}
示例10: queues
def queues(request):
queues = ResQ.queues(HOST)
failure_count = Failure.count(ResQ(HOST))
template = env.get_template('queues.html')
dic = {
'queues':queues,
'failure_count':failure_count,
'resq': resq
}
return str(template.render(dic))
示例11: failed_retry
def failed_retry(request):
try:
import json
except ImportError:
import simplejson as json
failed_job = request.POST['failed_job']
job = b64decode(failed_job)
decoded = ResQ.decode(job)
failure.retry(HOST, decoded['queue'], job)
raise Redirect('/failed/')
示例12: save
def save(self, resq):
data = {
'failed_at' : str(datetime.datetime.now()),
'payload' : self._payload,
'error' : self._parse_message(self._exception),
'backtrace' : self._parse_traceback(self._traceback),
'queue' : self._queue
}
data = ResQ.encode(data)
resq.redis.push('failed', data)
示例13: failed_job
def failed_job(request, retry=False):
failed_job_ = request.POST['failed_job']
job = b64decode(failed_job_)
if retry:
# post /failed/retry
decoded = ResQ.decode(job)
failure.retry(get_pyres(), decoded['queue'], job)
else:
# post /failed/delete
failure.delete(get_pyres(), job)
return redirect('resweb-failed')
示例14: __init__
def __init__(self, server="localhost:6379", password=None):
"""
>>> from pyres.scheduler import Scheduler
>>> scheduler = Scheduler('localhost:6379')
"""
self._shutdown = False
if isinstance(server, basestring):
self.resq = ResQ(server=server, password=password)
elif isinstance(server, ResQ):
self.resq = server
else:
raise Exception("Bad server argument")
示例15: submit_feedback
def submit_feedback(request):
if request.method != 'POST':
raise Http404
if 'lang' in request.GET and request.GET['lang'] in ALLOWED_LANGS:
translation.activate(request.GET['lang'])
try:
form = FeedbackForm(request.POST or None)
if form.is_valid():
r = ResQ()
r.enqueue(FeedbackTask, form.cleaned_data['name'],
form.cleaned_data['email'], form.cleaned_data['text'])
return HttpResponse(status=200)
# form is invalid
return HttpResponse(
loader.render_to_string('feedback/feedback_form_partial.html',
{'feedback_form': form}),
status=409)
except Exception:
logger.exception('')
raise