def get_param_dict(start_time,param_dict_str): param_dict = {} #默认时间参数 time = datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S") cur_time = start_time cur_hour = time.strftime('%Y%m%d%H') cur_date = time.strftime('%Y%m%d') last_hour = (time - datetime.timedelta(hours=1)).strftime('%Y%m%d%H') last_two_hour = (time - datetime.timedelta(hours=2)).strftime('%Y%m%d%H') last_date = (time - datetime.timedelta(days=1)).strftime('%Y%m%d') last_two_date = (time - datetime.timedelta(days=2)).strftime('%Y%m%d') param_dict['cur_time'] = cur_time param_dict['cur_hour'] = cur_hour param_dict['cur_date'] =cur_date param_dict['last_hour'] =last_hour param_dict['last_two_hour'] =last_two_hour param_dict['last_date'] =last_date param_dict['last_two_date'] =last_two_date #默认目录参数 default_params = get_conf(CONFILE).items('assistant_param') for k,v in default_params: param_dict[k] = v #页面传参 try: if param_dict_str!='': dicts = param_dict_str.split(',') for d in dicts: item = d.split(':') key = item[0] value = item[1] param_dict[key] = value except Exception,e: print e
def get_param_dict(execid,param_dict_str): sysout('获取所有替换参数值 ') #之前是用流程的启动时间来计算,在阻塞时会有问题,更新为通过执行时间来计算 sql = '''select from_unixtime(floor(submit_time/1000),'%%Y-%%m-%%d %%H:%%i:%%s') from execution_flows t where exec_id=%s''' % execid db = get_db() start_time, = db.fetch_one(sql) sysout('流程的提交时间为:%s' % start_time) param_dict = {} #默认时间参数 time = datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S") cur_time = start_time cur_hour = time.strftime('%Y%m%d%H') cur_date = time.strftime('%Y%m%d') last_hour = (time - datetime.timedelta(hours=1)).strftime('%Y%m%d%H') last_two_hour = (time - datetime.timedelta(hours=2)).strftime('%Y%m%d%H') last_date = (time - datetime.timedelta(days=1)).strftime('%Y%m%d') last_two_date = (time - datetime.timedelta(days=2)).strftime('%Y%m%d') param_dict['cur_time'] = cur_time param_dict['cur_hour'] = cur_hour param_dict['cur_date'] =cur_date param_dict['last_hour'] =last_hour param_dict['last_two_hour'] =last_two_hour param_dict['last_date'] =last_date param_dict['last_two_date'] =last_two_date #配置中的默认参数 default_params = get_conf(CONFILE).items('job_replace_param') for k,v in default_params: param_dict[k] = v #页面传参 try: if param_dict_str!='': dicts = param_dict_str.split(',') for d in dicts: item = d.split(':') key = item[0] value = item[1] param_dict[key] = value except Exception,e: sysout(e)
import os import zipfile import urllib import urllib2 import json import commands CURRENTPATH = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(CURRENTPATH, '..')) from util.helpers import mysql_helper from job_define import Job,MyScheduleException from util.config import get_conf #配置文件 CONFILE = "%s/../conf/nice.cfg" % CURRENTPATH azkaban_url = get_conf(CONFILE).get('web_param','azkaban_url') #执行脚本 def generate_files(username='',session_id=''): #1/清空所有文件 dir_path = '%s/../files/' % CURRENTPATH os.system('rm -rf %s' % dir_path) os.system('mkdir %s' % dir_path) #2/生成文件目录 #3/生成文件 job_list = Job.get_alljobs(login_user=username) for job in job_list: #2/生成文件目录 project_path = dir_path+job.project_name+'/' zip_path = dir_path+job.project_name+'.zip'
def __init__(self, dbconfig): self._conf = get_conf(dbconfig)
import tornado.ioloop import tornado.web import tornado.options from handler.job_list import JobListHandler from handler.job_to_update import JobToUpdateHandler from handler.job_update import JobUpdateHandler from handler.job_delete import JobDeleteHandler from handler.job_upload import JobUploadHandler from handler.job_check_exist import JobCheckExistHandler from handler.hive_index import HiveIndexHandler from handler.dag_edit import DagOpHandler #默认端口 from tornado.options import define, options from util.config import get_conf assistant_port= get_conf(CONFILE).get('web_param','assistant_port') define("port", default=assistant_port, help="run on the given port", type=int) #log日志配置 def init_logconfig(): log_file = 'schedule_web.log' logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s - %(message)s', datefmt='', filename=log_file, filemode='a') settings = { "template_path":os.path.join(os.path.dirname(__file__), "../templates"), "static_path": os.path.join(os.path.dirname(__file__), "../static")