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


Python Tasks.find方法代碼示例

本文整理匯總了Python中tasks.models.Tasks.find方法的典型用法代碼示例。如果您正苦於以下問題:Python Tasks.find方法的具體用法?Python Tasks.find怎麽用?Python Tasks.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tasks.models.Tasks的用法示例。


在下文中一共展示了Tasks.find方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_fail_on_travis_api_error

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
 def test_fail_on_travis_api_error(self):
     """Test fail on travis api error"""
     travis_ci.requests.get.side_effect = Exception
     data = self._create_task()
     with LogCapture() as log_capture:
         travis_ci.travis_ci_service(data).should.be.none
         list(log_capture.actual())[0].should.contain('ERROR')
     Tasks.find({}).count().should.be.equal(0)
開發者ID:coviolations,項目名稱:coviolations_web,代碼行數:10,代碼來源:test_travis_ci.py

示例2: test_fail_if_already_exists

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
 def test_fail_if_already_exists(self):
     """Test fail if job already exists"""
     self._create_task()
     data = self._create_task()
     with LogCapture() as log_capture:
         travis_ci.travis_ci_service(data).should.be.none
         list(log_capture.actual())[0].should.contain('ERROR')
     Tasks.find({}).count().should.be.equal(1)
開發者ID:coviolations,項目名稱:coviolations_web,代碼行數:10,代碼來源:test_travis_ci.py

示例3: test_fail_on_wrong_project

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
 def test_fail_on_wrong_project(self):
     """Test fail on wrong project"""
     travis_ci.requests.get.return_value = MagicMock(
         json=MagicMock(return_value={
             'repository_id': 2,
             'slug': 'wrong',
         })
     )
     data = self._create_task()
     with LogCapture() as log_capture:
         travis_ci.travis_ci_service(data).should.be.none
         list(log_capture.actual())[0].should.contain('ERROR')
     Tasks.find({}).count().should.be.equal(0)
開發者ID:coviolations,項目名稱:coviolations_web,代碼行數:15,代碼來源:test_travis_ci.py

示例4: test_fail_with_wrong_project

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
 def test_fail_with_wrong_project(self):
     """Test fail with wrong project"""
     task_id = Tasks.save({
         'project': 'test',
         'service': {
             'name': 'token',
             'token': ProjectFactory().token,
         }
     })
     data = Tasks.find_one(task_id)
     with LogCapture() as log_capture:
         token_service(data).should.be.none
         list(log_capture.actual())[0].should.contain('ERROR')
     Tasks.find({}).count().should.be.equal(0)
開發者ID:coviolations,項目名稱:coviolations_web,代碼行數:16,代碼來源:test_token.py

示例5: get_context_data

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
    def get_context_data(self, **kwargs):
        """Get day statistic"""
        success = Tasks.find({'created': {
            '$gte': datetime.now() - timedelta(days=1)
        }, 'status': STATUS_SUCCESS}).count()

        failed = Tasks.find({'created': {
            '$gte': datetime.now() - timedelta(days=1)
        }, 'status': STATUS_FAILED}).count()

        if failed:
            failed_percent = failed * 100 / (success + failed)
        else:
            failed_percent = 0

        return {
            'failed': failed_percent,
            'success': 100 - failed_percent,
            'debug': settings.DEBUG,
            'site': Site.objects.get_current(),
        }
開發者ID:coviolations,項目名稱:coviolations_web,代碼行數:23,代碼來源:views.py

示例6: _fill_statistic_parts

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
 def _fill_statistic_parts(self, parts, grouper):
     """Fill statistic parts"""
     for task in Tasks.find({
         'project': self.name,
         'created': {'$exists': True},
         'success_percent': {'$exists': True},
     }):
         if type(task['created']) is datetime:
             group = grouper(task)
             parts[group]['count'] += 1
             parts[group]['sum_percent'] +=\
                 task['success_percent']
             parts[group][
                 'success' if task['status'] == STATUS_SUCCESS else 'failed'
             ] += 1
開發者ID:michaeljoseph,項目名稱:coviolations_web,代碼行數:17,代碼來源:models.py

示例7: get_success_percents

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
 def get_success_percents(self, count, branch=None):
     """Get project last success percents"""
     if branch is None:
         branch = self.dashboard_branch
     spec = {
         'project': self.name,
     }
     if branch:
         spec['commit.branch'] = branch
     return [
         task.get('success_percent', 0) for task in Tasks.find(
             spec, sort=[('created', DESCENDING)], fields={
                 'success_percent': True,
             }, limit=count)
     ]
開發者ID:michaeljoseph,項目名稱:coviolations_web,代碼行數:17,代碼來源:models.py

示例8: travis_ci_service

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
def travis_ci_service(data):
    """Create tasks from data received from travis-c

    :param data: Data received from service
    :type data: dict
    :returns: bson.ObjectId or None -- pk of created task
    """
    try:
        assert Tasks.find({
            'service.name': 'travis_ci',
            'service.job_id': data['service']['job_id'],
        }).count() <= 1

        job = requests.get(
            'https://api.travis-ci.org/jobs/{}'.format(
                data['service']['job_id'],
            ),
        ).json()

        repo = requests.get(
            'https://api.travis-ci.org/repos/{}'.format(
                job['repository_id'],
            ),
        ).json()

        # TODO: add pull request support
        assert data['project'] == repo['slug']

        if data['service'].get('pull_request_id'):
            pull_request = data['service']['pull_request_id']
            if pull_request != 'false':
                data['pull_request_id'] = int(
                    data['service']['pull_request_id'],
                )

        return Tasks.save(data)
    except Exception as e:
        # remove task on error
        Tasks.remove(data['_id'])
        logger.exception('Travis-ci service fail: {}'.format(e))
開發者ID:coviolations,項目名稱:coviolations_web,代碼行數:42,代碼來源:travis_ci.py

示例9: branches

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
 def branches(self):
     """Get project branches"""
     return Tasks.find({'project': self.name}).distinct('commit.branch')
開發者ID:michaeljoseph,項目名稱:coviolations_web,代碼行數:5,代碼來源:models.py

示例10: handle

# 需要導入模塊: from tasks.models import Tasks [as 別名]
# 或者: from tasks.models.Tasks import find [as 別名]
 def handle(self, *args, **kwargs):
     for task in Tasks.find({}, sort=[('created', ASCENDING)]):
         try:
             prepare_violations(task['_id'])
         except Exception as e:
             print e
開發者ID:coviolations,項目名稱:coviolations_web,代碼行數:8,代碼來源:recreate_violations.py


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