Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Makes ProgressBar.increment() method thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
dkliban committed Dec 2, 2016
1 parent 251ec21 commit 428802d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
@@ -1,10 +1,15 @@
dist: trusty
sudo: false
language: python
python:
- "3.4"
- "3.5"
addons:
postgresql: "9.3"
sonarqube:
token: "8ac245c4c882063ecd40896cae13e028efd8681d"
jdk:
- oraclejdk8
install:
- "pip install -r test_requirements.txt"
- "pushd app/ && python setup.py develop && popd"
Expand All @@ -18,3 +23,5 @@ before_script:
script:
- "flake8 --config flake8.cfg app/"
- "app/pulp/app/db-reset.sh && python manage.py test app"
- sonar-scanner -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST -Dsonar.github.repository=$TRAVIS_REPO_SLUG -Dsonar.analysis.mode=preview -Dsonar.github.oauth=08368a91e061e61371abf238284ba47a343fc09c

17 changes: 10 additions & 7 deletions app/pulp/app/models/progress.py
Expand Up @@ -4,9 +4,9 @@
from gettext import gettext as _
import logging

from django.db import models
from django.db import models, transaction

from pulp import tasking
from pulp.tasking import util
from pulp.app.models import Model, Task

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -66,7 +66,7 @@ def save(self, *args, **kwargs):
kwargs (dict): keyword arguments to be passed on to the real save
"""
if self.task_id is None:
self.task_id = Task.objects.get(id=tasking.get_current_task_id())
self.task_id = Task.objects.get(id=util.get_current_task_id())
super(ProgressReport, self).save(*args, **kwargs)

def __enter__(self):
Expand Down Expand Up @@ -193,10 +193,13 @@ def increment(self):
This will increment and save the self.done attribute which is useful to put into a loop
processing items.
"""
self.done += 1
if self.done > self.total:
_logger.warning(_('Too many items processed for ProgressBar %s') % self.message)
self.save()
with transaction.atomic():
self.done = models.F('done') + 1
self.save()
np = ProgressBar.objects.get(id=self.id)
print('done = ' + str(np.done))
#if self.done > self.total:
# _logger.warning(_('Too many items processed for ProgressBar %s') % self.message)

def iter(self, iter):
"""
Expand Down
5 changes: 5 additions & 0 deletions sonar-project.properties
@@ -0,0 +1,5 @@
sonar.projectKey=org.redhat:pulp
sonar.projectName=Pulp
sonar.projectVersion=3.0
sonar.sources=.

0 comments on commit 428802d

Please sign in to comment.