7 发布演示
8 jenkins
发布演示
结合Jenkins部署
调用Jenkins-api
基于Jenkins-api的数据库表设计
代码
from django.shortcuts import render,HttpResponse,redirect
from django.views import View
from demo1 import models
from demo1.task import add
from celery.result import AsyncResult
from 发布.celery import app
def fabu(request):
if request.method=='GET':
env=models.RecordEnv.objects.all()
return render(request,'fabu.html',locals())
else:
env=request.POST.get('env')
app=request.POST.get('app')
obj\_li = models.App.objects.filter(name=app,environment\_\_name=env)
#拿到 对应的 主机组 代码-->地址
#循环 主机组 推送代码
app_name = 'payment'
host_li = \[{'id':'test','path':'/app/www/payment'},\]
package = 'svn://xxxxx' #sh xxxx.sh
return HttpResponse('已存入队列中')
def celery_status(req):
import datetime
import json
if req.method=='GET':
if req.GET.get('x') and req.GET.get('y'):
# 立即执行
# ret=add.delay(int(req.GET.get('x')),int(req.GET.get('y')))
if req.GET.get('after'):
ctime = datetime.datetime.now()
utc_ctime = datetime.datetime.utcfromtimestamp(ctime.timestamp())
s1 = datetime.timedelta(seconds=int(req.GET.get('after'))*60)
ctime\_x = utc\_ctime + s1
# 使用apply_async并设定时间
year=req.GET.get('year')
mouth=req.GET.get('month')
day=req.GET.get('day')
hour=req.GET.get('hour')
minute=req.GET.get('minute')
if year and mouth and day and hour and minute:
ctime = datetime.datetime(year=int(year), month=int(mouth),
day=int(day), hour=int(hour), minute=int(minute))
# 把当前本地时间转换成UTC时间
ctime_x = datetime.datetime.utcfromtimestamp(ctime.timestamp())
if ctime_x:
#最核心的 语句
ret = add.apply\_async(args=\[int(req.GET.get('x')), int(req.GET.get('y'))\], eta=ctime\_x)
num=ret.id
if req.GET.get('cancel'):
async = AsyncResult(id=req.GET.get('cancel'), app=app)
async.revoke(terminate=True)
cancel_tag='取消成功'
if req.GET.get('stop'):
async = AsyncResult(id=req.GET.get('stop'), app=app)
async.revoke()
stop_tag='中止成功'
return render(req,'celery.html',locals())
else:
ret=req.POST.get('id','')
data = ''
if ret:
async=AsyncResult(id=ret,app=app)
if async.successful():
data='执行成功,数据是:'+str(async.get())
async.forget()
elif async.failed():
data='执行失败'
elif async.status=='PENDING':
data='等待被执行'
elif async.status=='RETPY':
data='任务异常正在重试'
elif async.status=='STARTED':
data='任务正在执行'
else:
data='未知'
return render(req,'celery.html',locals())
jenkins
结合jenkins部署
调用jerkins-api
项目:
测试环境
生产环境
参考文档