本文整理汇总了Python中gearman.GearmanClient.do_task方法的典型用法代码示例。如果您正苦于以下问题:Python GearmanClient.do_task方法的具体用法?Python GearmanClient.do_task怎么用?Python GearmanClient.do_task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gearman.GearmanClient
的用法示例。
在下文中一共展示了GearmanClient.do_task方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from gearman import GearmanClient [as 别名]
# 或者: from gearman.GearmanClient import do_task [as 别名]
def send(self):
log.error("in send of email api")
emailjson = json.loads(self.request.body)
if emailjson and 'template_name' in emailjson:
log.error("weehah, body json = %s" % emailjson)
#TODO: revamp and use self.db.gearman_client
gearman_client = GearmanClient(options.gearman_servers)
gearman_client.do_task(Task("email_send",self.request.body, background=True))
示例2: send_email
# 需要导入模块: from gearman import GearmanClient [as 别名]
# 或者: from gearman.GearmanClient import do_task [as 别名]
def send_email(name,user,data):
jsondict = {
'template_name':name,
'emails':[user.email],
'template_data':data,
'apikey':options.demisauce_api_key
}
data = json.dumps(jsondict)
url = "%s/api/email/%s/send.json?apikey=%s" % (options.demisauce_url,name,options.demisauce_api_key)
gearman_client = GearmanClient(options.gearman_servers)
gearman_client.do_task(Task("email_send",data, background=True))
示例3: test_mailchimp
# 需要导入模块: from gearman import GearmanClient [as 别名]
# 或者: from gearman.GearmanClient import do_task [as 别名]
def test_mailchimp():
'test mailchimp integration'
"""
For more info about setting config settings see demisauce/manage.py
"""
from gearman import GearmanClient
from gearman.task import Task
gearman_client = GearmanClient(options.gearman_servers)
#send emails
list_id, mc_apikey = '0',''
site = Site.GET(1)
assert site.has_attribute('mailchimp_api_key')
assert site.has_attribute('mailchimp_listid')
list_id = site.get_attribute('mailchimp_listid').value
mc_apikey = site.get_attribute('mailchimp_api_key').value
jsondict = {
'template_name':'thank_you_for_registering_with_demisauce',
'user':{"email":"[email protected]"},
'mailchimp_listid':list_id,
'mailchimp_api_key':mc_apikey,
'attributes':[{"name":"BetaUsers","category":"event"},{"name":"NewSegment3","category":"event"}]
}
#'BetaUsers',"NewSegment","NewSegment2"
num_sent = gearman_client.do_task(Task("mailchimp_addtolist",json.dumps(jsondict), background=False))
logging.debug("test emailsend num_sent = %s" % (num_sent))
assert num_sent == '1'
示例4: TestGearman
# 需要导入模块: from gearman import GearmanClient [as 别名]
# 或者: from gearman.GearmanClient import do_task [as 别名]
class TestGearman(unittest.TestCase):
def setUp(self):
self.last_exception = (None, None)
self.worker = GearmanWorker(job_servers)
self.worker.register_function("echo", echo)
self.worker.register_function("fail", fail)
self.worker.register_function("sleep", sleep, timeout=1)
class Hooks(object):
@staticmethod
def start(job):
pass
@staticmethod
def complete(job, res):
pass
@staticmethod
def fail(job, exc):
self.last_exception = (job.func, exc)
import thread
thread.start_new_thread(self.worker.work, tuple(), dict(hooks=Hooks)) # TODO: Shouldn't use threads.. but we do for now (also, the thread is never terminated)
self.client = GearmanClient(job_servers)
def tearDown(self):
del self.worker
del self.client
def testComplete(self):
self.failUnlessEqual(self.client.do_task(Task("echo", "bar")), 'bar')
def testFail(self):
self.failUnlessRaises(self.client.TaskFailed, lambda:self.client.do_task(Task("fail", "bar")))
# self.failUnlessEqual(self.last_exception[0], "fail")
def testTimeout(self):
self.failUnlessEqual(self.client.do_task(Task("sleep", "0.1")), '0.1')
self.failUnlessRaises(self.client.TaskFailed, lambda:self.client.do_task(Task("sleep", "1.5")))
def testCall(self):
self.failUnlessEqual(self.client("echo", "bar"), 'bar')
示例5: stash_file
# 需要导入模块: from gearman import GearmanClient [as 别名]
# 或者: from gearman.GearmanClient import do_task [as 别名]
def stash_file(base64file,filename=None,gearman_client=None,args={}):
"""Accepts file handle from http upload, stashes, creates gearman worker"""
new_file = ''.join([random.choice(string.letters + string.digits) for i in range(15)])
if filename == None:
extension = ".jpg"
else:
extension = re.search('\.\w+',filename).group()
new_path = '%s/%s' % (random.choice(string.ascii_lowercase),random.choice(string.ascii_lowercase)) # two folders
relative_path_wfile = '%s/%s' % (new_path,new_file)
#local_path_wfile = '%s/%s%s' % (path,new_file,extension)
if not gearman_client:
gearman_client = GearmanClient(options.gearman_servers)
json_data = {
'file':new_file,
'args':args,
'extension':extension,
'path':new_path,
'path_w_file':relative_path_wfile,
'url':'%sstatic/upload/%s%s' % (options.base_url,relative_path_wfile,extension),
'image':base64file
}
gearman_client.do_task(Task("image_resize",json.dumps(json_data), background=True))
return relative_path_wfile
示例6: test_background_counting
# 需要导入模块: from gearman import GearmanClient [as 别名]
# 或者: from gearman.GearmanClient import do_task [as 别名]
def test_background_counting(self, **kwargs):
client = GearmanClient(settings.GEARMAN_SERVERS)
res = client.do_task(Task("testapp.background_counting", None))
self.assertFalse(res)
示例7: test_reverse
# 需要导入模块: from gearman import GearmanClient [as 别名]
# 或者: from gearman.GearmanClient import do_task [as 别名]
def test_reverse(self, **kwargs):
client = GearmanClient(settings.GEARMAN_SERVERS)
sentence = 'The quick brown fox jumps over the lazy dog'
res = client.do_task(Task("testapp.reverse", sentence))
self.assertEqual(res, 'god yzal eht revo spmuj xof nworb kciuq ehT')