Skip to content

Commit

Permalink
Fixed several mistakes
Browse files Browse the repository at this point in the history
Some variables were undeclared or badly used
  • Loading branch information
jlebonzec committed Nov 29, 2017
1 parent c23d747 commit f8ede65
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 18 deletions.
3 changes: 2 additions & 1 deletion quantifiedcode/backend/api/v1/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def get(self, project_id, snapshot_a_id, snapshot_b_id, path=None):
diff_issue_occurrence_table.c.issue_occurrence == issue_occurrence_table.c.pk,
*issue_type_query))\
.join(issue_table, issue_table.c.pk == issue_occurrence_table.c.issue)\
.join(issue_classes_cte, issue_classes_cte.c.analyzer_code == issue_table.c.analyzer + ':' + issue_table.c.code)\
.join(issue_classes_cte, issue_classes_cte.c.analyzer_code == issue_table.c.analyzer + ':' + issue_table.c.code) \
.alias('select_table')

#we construct the table we will select issues from
file_revision_query = select([fr_table.c.pk])\
Expand Down
2 changes: 1 addition & 1 deletion quantifiedcode/backend/api/v1/public_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get(self):
form = PublicProjectsForm(request.args)

if not form.validate():
return {'message' : 'please correct the errors mentioned below', errors: form.errors}, 400
return {'message' : 'please correct the errors mentioned below', 'errors': form.errors}, 400

data = form.data

Expand Down
2 changes: 2 additions & 0 deletions quantifiedcode/backend/api/v1/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def get(self, project_id, snapshot_id, path=None):
.join(issue_occurrence_table, issue_occurrence_table.c.file_revision == snapshot_file_revisions_table.c.filerevision)\
.join(issue_table, and_(issue_table.c.pk == issue_occurrence_table.c.issue, issue_table.c.ignore == ignore) )\
.join(issue_classes_cte, issue_classes_cte.c.analyzer_code == issue_table.c.analyzer + ':' + issue_table.c.code)\
.alias('fr_select_table')

#we construct the file revisions query
file_revisions_query = select([snapshot_file_revisions_table.c.filerevision])\
Expand All @@ -124,6 +125,7 @@ def get(self, project_id, snapshot_id, path=None):
.join(issue_occurrence_table, issue_occurrence_table.c.file_revision == fr_table.c.pk)\
.join(issue_table, and_(issue_table.c.pk == issue_occurrence_table.c.issue, issue_table.c.ignore == ignore))\
.join(issue_classes_cte, issue_classes_cte.c.analyzer_code == issue_table.c.analyzer + ':' + issue_table.c.code)\
.alias('select_table')


#we construct the issues query
Expand Down
10 changes: 5 additions & 5 deletions quantifiedcode/backend/tasks/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, task, level=logging.INFO, backend=None, ping=True):

def __enter__(self):
kwargs = {
'filename': os.path.join(settings.get('backend.path'), settings.get('backend.paths.tasks'),
'filename': os.path.join(settings.get('project_path'), settings.get('backend.paths.tasks'),
self.task.pk + '.log'),
'encoding': "utf-8",
'mode': "w",
Expand Down Expand Up @@ -139,10 +139,10 @@ def task_is_being_processed(current_task=None):
try:
res = celery.AsyncResult(task.celery_task_id)
with self.backend.transaction():
if res.state == ResultState.Started:
if res.state == self.ResultState.Started:
self.backend.update(task, {'status': 'in_progress'})
return True
elif res.state == ResultState.Pending:
elif res.state == self.ResultState.Pending:
if task.get('last_ping'):
# if we haven't heard from the task in a while, we mark it as failed...
if datetime.datetime.now() - task.last_ping > datetime.timedelta(seconds=60 * 10):
Expand All @@ -151,9 +151,9 @@ def task_is_being_processed(current_task=None):
elif datetime.datetime.now() - task.created_at < datetime.timedelta(seconds=60 * 20):
self.backend.update(task, {'status': 'in_progress'})
return True
elif res.state == ResultState.Failure:
elif res.state == self.ResultState.Failure:
self.backend.update(task, {'status': 'failed'})
elif res.state == ResultState.Success:
elif res.state == self.ResultState.Success:
self.backend.update(task, {'status': 'succeeded'})
except Task.DoesNotExist:
# sometimes a task object will get deleted by another worker while
Expand Down
4 changes: 2 additions & 2 deletions quantifiedcode/backend/tasks/periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def delete_pending_project():

@celery.task(queue="delete", ignore_result=False, time_limit=3600)
def delete_pending_user():
pending_projects = backend.filter(User, {'delete': True}).sort('updated_at', 1).limit(100)
logger.debug("%d users marked for deletion" % len(pending_projects))
pending_users = backend.filter(User, {'delete': True}).sort('updated_at', 1).limit(100)
logger.debug("%d users marked for deletion" % len(pending_users))
for pending_user in pending_users:
return delete_user(pending_user.pk, task_id=delete_pending_user.request.id)
logger.debug("No users left to delete...")
Expand Down
2 changes: 2 additions & 0 deletions quantifiedcode/backend/tasks/project/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
from checkmate.management.commands.reset import Command as ResetCommand
from quantifiedcode.settings import settings, backend
from quantifiedcode.backend.settings import BACKEND_PATH
from quantifiedcode.backend.tasks.helpers import ExclusiveTask, TaskLogger

from ...worker import celery
from ...models import (Project,
Task,
UserRole,
IssueClass,
ProjectIssueClass)
from ..project.analyze import analyze_project

@celery.task(queue="analysis", ignore_result=False)
def delete_project(project_id, task_id=None):
Expand Down
2 changes: 2 additions & 0 deletions quantifiedcode/backend/utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

from quantifiedcode.settings import settings

from flask import jsonify
import logging
import traceback
logger = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions quantifiedcode/frontend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ def configure(app, settings):

if __name__ == '__main__':
app = get_app(settings)
debug = settings.get('debug')
app.run(debug=debug, host='0.0.0.0', port=8000,threaded = False)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from __future__ import print_function

import logging
import subprocess

from datetime import datetime
from flask import request
Expand Down
12 changes: 7 additions & 5 deletions quantifiedcode/plugins/git/backend/api/v1/resources/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ def post(self):
'url' : form.url.data
}

try:
project = create_project(project_data, git_data, user)
except DuplicateProject:
return ({'message': 'A project with the same name already exists for your account.'},
403)
project = create_project(project_data, git_data, user)
# FIXME: handle duplicate project exception
# try:
# pass
# except DuplicateProject:
# return ({'message': 'A project with the same name already exists for your account.'},
# 403)
return ({'message': 'success!',
'project': self.export(project)},
200)
8 changes: 4 additions & 4 deletions quantifiedcode/settings/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
backend:
url: /api
# by default, we use an in-memory instance of SQLite for testing.
db_url: 'postgresql://qc:password@db/quantified'
db_url: 'postgresql+psycopg2://qc:password@db/quantified'
db_url_test: 'sqlite:///qc_test.sqlite'
paths:
repositories: "data/repositories"
git_repositories: "data/repositories"
tasks: "data/tasks"
celery:
config:
Expand All @@ -15,8 +15,8 @@ backend:
timezone: Europe/Oslo
enable_utc: true
worker_hijack_root_logger: false
broker_url: 'amqp://guest:guest@rabbitmq:5672/'
result_backend: 'amqp://guest:guest@rabbitmq:5672/'
broker_url: 'redis://redis:6379/'
result_backend: 'redis://redis:6379/'
task_default_queue: tasks
task_queues:
- {name: tasks, routing_key: 'task'}
Expand Down

0 comments on commit f8ede65

Please sign in to comment.