Skip to content

Commit a4487e5

Browse files
author
chaoyiwang
committed
add utils for oplog
1 parent 13aac5f commit a4487e5

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

apis/views.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from django.core.urlresolvers import reverse
1616
from raven.contrib.django.raven_compat.models import client
1717
from log import logger, op_logger
18-
from oplog.models import add_oplog
18+
from oplog.utils import add_oplog
1919

2020

2121
def render_op_result(op_result):
@@ -729,22 +729,22 @@ def handle(app):
729729
return cls.deal_with_appname(appname, handle)
730730

731731
@classmethod
732-
def post_image_push(cls, appname, authors, commits):
732+
def post_image_push(cls, appname, authors):
733+
commitid_len = 40
734+
733735
def handle(app):
734-
try:
735-
app.check_latest_giturl()
736-
except InvalidLainYaml, e:
737-
return (400, None, '%s' % e, reverse('api_image_push', kwargs={'appname': appname}))
738-
commitid_len = 40
739736
datas = {
740737
"appname": appname,
741-
"commits": commits,
742-
"operator": AuthApi.operater,
738+
"image": app.meta_version,
743739
"lastid": app.meta_version[-commitid_len:],
744740
"nextid": app.latest_meta_version[-commitid_len:],
745741
"giturl": app.giturl,
746742
"authors": authors,
747743
}
744+
try:
745+
app.check_latest_giturl()
746+
except InvalidLainYaml, e:
747+
return (400, None, '%s' % e, reverse('api_image_push', kwargs={'appname': appname}))
748748
image_push_notify(datas)
749749
return (200, None, 'ok', reverse('api_image_push', kwargs={'appname': appname}))
750750
return cls.deal_with_appname(appname, handle)
@@ -1350,10 +1350,8 @@ def get_proc(app, pg_name):
13501350
for proc in app.lain_config.procs.values():
13511351
if "%s.%s.%s" % (app.appname, proc.type.name, proc.name) == pg_name:
13521352
return proc
1353-
13541353
def get_secret_files_bypass(app, pg_name):
13551354
return get_proc(app, pg_name).secret_files_bypass
1356-
13571355
def get_defined_secret_files(app, pg_name):
13581356
return get_proc(app, pg_name).secret_files
13591357

oplog/models.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from django.db import models
2-
from django.utils import timezone;
32

43
# Create your models here.
54

@@ -28,17 +27,4 @@ class OpLog(models.Model):
2827
time = models.DateTimeField()
2928
message = models.CharField(max_length=512)
3029

31-
def _add_oplog(user, op, app, app_version, message):
32-
try:
33-
time = timezone.localtime(timezone.now())
34-
oplog = OpLog(user=user, op=op, app=app,
35-
app_version=app_version, time=time, message=message)
36-
oplog.save()
37-
except:
38-
pass
39-
40-
def add_oplog(user, op, app, app_version, message):
41-
from threading import Thread
42-
t = Thread(target=_add_oplog, args=(user, op, app, app_version, message))
43-
t.start()
4430

oplog/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.utils import timezone;
2+
from threading import Thread
3+
4+
def _add_oplog(user, op, app, app_version, message):
5+
try:
6+
time = timezone.localtime(timezone.now())
7+
oplog = OpLog(user=user, op=op, app=app,
8+
app_version=app_version, time=time, message=message)
9+
oplog.save()
10+
except:
11+
pass
12+
13+
def add_oplog(user, op, app, app_version, message):
14+
t = Thread(target=_add_oplog, args=(user, op, app, app_version, message))
15+
t.start()
16+

0 commit comments

Comments
 (0)