本文整理汇总了Python中pyres.ResQ类的典型用法代码示例。如果您正苦于以下问题:Python ResQ类的具体用法?Python ResQ怎么用?Python ResQ使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResQ类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:nott,项目名称:kkb,代码行数:7,代码来源:__init__.py
示例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()
开发者ID:lapbay,项目名称:extra,代码行数:29,代码来源:jobs.py
示例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)
开发者ID:nott,项目名称:kkb,代码行数:7,代码来源:livejournal.py
示例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 []]
开发者ID:Affectiva,项目名称:pyres,代码行数:7,代码来源:worker.py
示例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'])
开发者ID:eiroh,项目名称:barista,代码行数:8,代码来源:eventq.py
示例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() == {}
开发者ID:duxiaoyao,项目名称:pyres,代码行数:12,代码来源:test_worker.py
示例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
开发者ID:TylerLubeck,项目名称:pyres,代码行数:27,代码来源:job.py
示例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
开发者ID:EG5h,项目名称:pyres,代码行数:9,代码来源:redis.py
示例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 = {}
开发者ID:aezell,项目名称:pyres,代码行数:9,代码来源:extensions.py
示例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))
开发者ID:deepu,项目名称:pyres,代码行数:10,代码来源:server.py
示例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/')
开发者ID:harikrishnan83,项目名称:pyres,代码行数:10,代码来源:server.py
示例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)
开发者ID:deepu,项目名称:pyres,代码行数:10,代码来源:failure.py
示例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')
开发者ID:geros,项目名称:pyres_django,代码行数:11,代码来源:views.py
示例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")
开发者ID:EG5h,项目名称:pyres,代码行数:12,代码来源:scheduler.py
示例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
开发者ID:nott,项目名称:django-pyres-feedback,代码行数:22,代码来源:views.py
示例16: retry
def retry(self, payload_class, args):
retry_every = getattr(payload_class, "retry_every", None)
retry_timeout = getattr(payload_class, "retry_timeout", 0)
if retry_every:
now = ResQ._utcnow()
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
开发者ID:duxiaoyao,项目名称:pyres,代码行数:13,代码来源:job.py
示例17: add_repository_to_queue
def add_repository_to_queue(user, repo_owner, repository_name, repo_object=None):
res = ResQ()
repo = None
token = user.get_profile().extra_data['access_token']
if not repo_object:
gh = Github(login=user.email, token=token)
repo = gh.repos.get(repo_owner, repository_name)
else:
repo = repo_object
queue_data = {'email': user.email, 'token': token}
queue_data['repo'] = {
'name': repo.name,
'url': repo.url,
'git_url': repo.git_url,
'html_url': repo.html_url,
'language': repo.language
}
db_repo, created = Repository.objects.get_or_create(
git_url=repo.git_url, defaults=queue_data['repo'])
query_filter = {'user': user, 'repository': db_repo}
query_filter.update({'defaults': {
'user': user,
"repository": db_repo
}
})
as_contributor, created = Contributor.objects.get_or_create(**query_filter)
# put a timestamp field in repository model to verify if there is need to
# process again. so only put in queue if is not created and timestamp > x time
res.enqueue(RepositoryWorker, queue_data)
开发者ID:timehome,项目名称:djangodash2012,代码行数:38,代码来源:models.py
示例18: save
def save(self, resq=None):
if not resq:
resq = 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
}
if self._worker:
data['worker'] = self._worker
data = ResQ.encode(data)
resq.redis.rpush('resque:failed', data)
开发者ID:aezell,项目名称:pyres,代码行数:14,代码来源:redis.py
示例19: save
def save(self, resq=None):
if not resq:
resq = 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,
}
if self._worker:
data["worker"] = self._worker
data = ResQ.encode(data)
resq.redis.push("resque:failed", data)
开发者ID:thomasst,项目名称:pyres,代码行数:14,代码来源:redis.py
示例20: main
def main(args=None):
if args is None:
args = sys.argv[1:]
parser = argparse.ArgumentParser()
parser.add_argument('--conf', '-c', help="Path to configuration file.")
parser.add_argument('--verbose', '-v', action='count', default=0, help='Log level: v=warning, vv=info, vvv=debug.')
options = parser.parse_args(args)
log_level = LOGS[options.verbose].upper()
logging.basicConfig(
level=getattr(logging, log_level),
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
if options.conf:
cfg = Config.load(abspath(expanduser(options.conf)))
else:
cfg = Config()
conn = ResQ(server="%s:%s" % (cfg.REDIS_HOST, cfg.REDIS_PORT), password=cfg.REDIS_PASSWORD)
conn.config = cfg
connect(
cfg.MONGO_DB,
host=cfg.MONGO_HOST,
port=cfg.MONGO_PORT,
username=cfg.MONGO_USER,
password=cfg.MONGO_PASS
)
print
print("--- Wight worker started ---")
print
Worker.run([WorkerJob.queue], conn)
print
print "--- Wight worker killed ---"
print
开发者ID:heynemann,项目名称:wight,代码行数:37,代码来源:__init__.py
注:本文中的pyres.ResQ类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论