Skip to content

Commit

Permalink
add utils for oplog
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoyiwang committed Jul 26, 2017
1 parent 13aac5f commit a4487e5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
20 changes: 9 additions & 11 deletions 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 Expand Up @@ -729,22 +729,22 @@ def handle(app):
return cls.deal_with_appname(appname, handle)

@classmethod
def post_image_push(cls, appname, authors, commits):
def post_image_push(cls, appname, authors):
commitid_len = 40

def handle(app):
try:
app.check_latest_giturl()
except InvalidLainYaml, e:
return (400, None, '%s' % e, reverse('api_image_push', kwargs={'appname': appname}))
commitid_len = 40
datas = {
"appname": appname,
"commits": commits,
"operator": AuthApi.operater,
"image": app.meta_version,
"lastid": app.meta_version[-commitid_len:],
"nextid": app.latest_meta_version[-commitid_len:],
"giturl": app.giturl,
"authors": authors,
}
try:
app.check_latest_giturl()
except InvalidLainYaml, e:
return (400, None, '%s' % e, reverse('api_image_push', kwargs={'appname': appname}))
image_push_notify(datas)
return (200, None, 'ok', reverse('api_image_push', kwargs={'appname': appname}))
return cls.deal_with_appname(appname, handle)
Expand Down Expand Up @@ -1350,10 +1350,8 @@ def get_proc(app, pg_name):
for proc in app.lain_config.procs.values():
if "%s.%s.%s" % (app.appname, proc.type.name, proc.name) == pg_name:
return proc

def get_secret_files_bypass(app, pg_name):
return get_proc(app, pg_name).secret_files_bypass

def get_defined_secret_files(app, pg_name):
return get_proc(app, pg_name).secret_files

Expand Down
14 changes: 0 additions & 14 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 @@ -28,17 +27,4 @@ class OpLog(models.Model):
time = models.DateTimeField()
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

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

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()

0 comments on commit a4487e5

Please sign in to comment.