Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use another thread to save oplog #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from django.core.urlresolvers import reverse
from raven.contrib.django.raven_compat.models import client
from log import logger, op_logger
from oplog.models import add_oplog
from oplog.utils import add_oplog


def render_op_result(op_result):
Expand Down
25 changes: 25 additions & 0 deletions oplog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='OpLog',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('user', models.CharField(max_length=64)),
('op', models.CharField(max_length=16)),
('app', models.CharField(max_length=32)),
('app_version', models.CharField(max_length=128)),
('time', models.DateTimeField()),
('message', models.CharField(max_length=512)),
],
),
]
9 changes: 0 additions & 9 deletions oplog/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models
from django.utils import timezone;

# Create your models here.

Expand Down Expand Up @@ -29,11 +28,3 @@ class OpLog(models.Model):
message = models.CharField(max_length=512)


def add_oplog(user, op, app, app_version, message):
try:
time = timezone.localtime(timezone.now())
oplog = OpLog(user=user, op=op, app=app,
app_version=app_version, time=time, message=message)
oplog.save()
except:
pass
16 changes: 16 additions & 0 deletions oplog/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.utils import timezone;
from threading import Thread

def _add_oplog(user, op, app, app_version, message):
try:
time = timezone.localtime(timezone.now())
oplog = OpLog(user=user, op=op, app=app,
app_version=app_version, time=time, message=message)
oplog.save()
except:
pass

def add_oplog(user, op, app, app_version, message):
t = Thread(target=_add_oplog, args=(user, op, app, app_version, message))
t.start()