def handler(signum, frame): j_logger.info('Signal handler called with signal %s' % str(signum)) #判断当前的JOB的status,如果为working,则sleep等待,否则直接退出 #JOB_STATUS 应该lock,readonly retry_times = 10 #设定timeout机制,如果进程长时间没有结束,则直接杀死;以后改成可配置 for job in get_all_jobs(): normal_quit = 0 #0代表正常退出 j_logger.info('trying terminate job %s !' % job.name) while job.run_status.value == JOB_WORKING: j_logger.info('job running,wait till it done!') time.sleep(0.5) retry_times -= 1 if retry_times <= 0: normal_quit = 1 break if normal_quit == 1: j_logger.info( 'job %s taken too long to finish,the scheduler will try to kill it violently!' % job.name) if (check_pid(job.process_id)): os.kill(job.process_id, signal.SIGKILL) #杀死子进程 j_logger.info('job %s was killed !' % job.name) else: j_logger.warn('job %s was not found!(error termination)' % job.name)
def start_sched(): j_logger.info(u'starting job scheduler ...') jobs = get_all_jobs() for job in jobs: j_logger.info(u'starting job %s ' % job.name) job.run_status = Value('i', 0) #job的状态值 try: p = Process(target=_inner_job, name=job.name,args=(job,)) p.start() job.process_id = p.pid j_logger.info(u'job %s started !' % job.name) except Exception as e: j_logger.error(u'job %s fail to start,due to [%s]!' % (job.name,e)) register_signal_notify() j_logger.info(u'job scheduler started !')
def start_sched(): j_logger.info(u'starting job scheduler ...') jobs = get_all_jobs() for job in jobs: j_logger.info(u'starting job %s ' % job.name) job.run_status = Value('i', 0) #job的状态值 try: p = Process(target=_inner_job, name=job.name, args=(job, )) p.start() job.process_id = p.pid j_logger.info(u'job %s started !' % job.name) except Exception as e: j_logger.error(u'job %s fail to start,due to [%s]!' % (job.name, e)) register_signal_notify() j_logger.info(u'job scheduler started !')
def handler(signum,frame): j_logger.info('Signal handler called with signal %s' % str(signum)) #判断当前的JOB的status,如果为working,则sleep等待,否则直接退出 #JOB_STATUS 应该lock,readonly retry_times = 10 #设定timeout机制,如果进程长时间没有结束,则直接杀死;以后改成可配置 for job in get_all_jobs(): normal_quit = 0 #0代表正常退出 j_logger.info('trying terminate job %s !' % job.name) while job.run_status.value == JOB_WORKING: j_logger.info('job running,wait till it done!') time.sleep(0.5) retry_times -= 1 if retry_times <= 0: normal_quit = 1 break if normal_quit == 1: j_logger.info('job %s taken too long to finish,the scheduler will try to kill it violently!' % job.name) if(check_pid(job.process_id)): os.kill(job.process_id, signal.SIGKILL) #杀死子进程 j_logger.info('job %s was killed !' % job.name) else: j_logger.warn('job %s was not found!(error termination)' % job.name)