本文整理汇总了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)
示例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)
示例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)
示例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)
示例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(),
}
示例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
示例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)
]
示例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))
示例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')
示例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