當前位置: 首頁>>代碼示例>>Python>>正文


Python GearmanClient.do_task方法代碼示例

本文整理匯總了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))
開發者ID:araddon,項目名稱:demisauce,代碼行數:10,代碼來源:api.py

示例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))
開發者ID:araddon,項目名稱:demisauce,代碼行數:13,代碼來源:actions.py

示例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'
開發者ID:araddon,項目名稱:demisauce,代碼行數:28,代碼來源:test_api.py

示例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')
開發者ID:chetan,項目名稱:fremen,代碼行數:40,代碼來源:tests.py

示例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
開發者ID:araddon,項目名稱:demisauce,代碼行數:26,代碼來源:assetmgr.py

示例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)
開發者ID:sekimura,項目名稱:django-gearman,代碼行數:6,代碼來源:tests.py

示例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')
開發者ID:sekimura,項目名稱:django-gearman,代碼行數:7,代碼來源:tests.py


注:本文中的gearman.GearmanClient.do_task方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。