Exemplo n.º 1
0
def DoResumePayDown(companyid, siteid, syncid, fromsitecode, ownpay, taskid):
    try:
        if ownpay == 'T':
            handler = SiteConfig.GetTaskHandler(companyid, siteid, taskid)
        else:
            # 获取公用账号企业ID
            common_companyid = 0
            handler = SiteConfig.GetTaskHandler(common_companyid, siteid,
                                                taskid)
        # 账号未验证通过
        if handler.bind.check_status == 10:
            raise CompanyAccountInvalidError(companyid, siteid, u'账号登录失败')
        try:
            handler.resume_searcher_down(fromsitecode, syncid, companyid)
            # 任务状态回写
            task = ResSyncDistribute.queryWithId(syncid)
            if HANDLE_STATUS.SUCCESS == handler.status:
                task.sync_status = 2010
                logger.info(u'<{}>下载付费简历<{}>成功!'.format(
                    handler.name, fromsitecode, handler.message))
            else:
                task.sync_status = 10
                task.error_message = handler.message
                logger.error(u'<{}>下载付费简历<{}>失败,原因:{}'.format(
                    handler.name, fromsitecode, handler.message))
            task.save()
        except BaseException as e:
            raise UnHandleRuntimeError(e)
    except BaseError as e:
        task = DBTask.queryWithId(syncid)
        task.sync_status = 10
        task.fail_num += 1
        task.log_info = e.message
        task.save()
Exemplo n.º 2
0
def CheckResumeSearchDownStat(taskid):
    key = Conf.RESUME_IMPORT_HKEY % taskid
    stat = ResumeRedisCli.hgetall(key)
    if stat:
        # finish
        finish = int(stat.get('finish', '0'))
        if finish:
            # 统计信息
            total = int(stat['total'])
            grab = int(stat['grab'])
            succ = int(stat['success'])
            ignore = int(stat['ignore'])
            fail = int(stat['failure'])
            # 来源信息
            siteid = int(stat['siteid'])
            importid = stat['importid']
            companyid = int(stat['companyid'])
            imphistoryid = int(stat['imphistoryid'])
            #
            task = ResSyncDistribute.queryWithId(importid)
            if task:
                if total > 0 and total <= succ + ignore + fail:
                    if total <= succ + ignore + fail:
                        if ResumeRedisCli.delete(key):
                            imp = ImpHistory.queryByHistoryId(imphistoryid)
                            if imp:
                                imp.succ_num = succ
                                imp.fail_num = fail
                                imp.end_time = datetime.today()
                                imp.proc_status = 1
                                if imp.succ_num == 0:
                                    imp.is_valid = 'F'
                                imp.save()
                            # 更改简历状态
                            ResumeBase.changeStat(task.resume_code)
                            # 回写任务状态
                            msg = u'<{}>下载付费简历总数<{}>,下载数<{}>,成功数<{}>,重复数<{}>,失败数<{}>.'.format(
                                SiteConfig.getSiteNameById(siteid), total,
                                grab, succ, ignore, fail)
                            task.sync_status = 20
                            task.error_message = ''
                            task.process_time = datetime.today()
                            task.save()
                            logger.info(msg)
                            dtc. async ('zpb.service.handleservice.DoInfo',
                                        *(companyid, siteid, taskid))
                elif total == 0:
                    if ResumeRedisCli.delete(key):
                        ImpHistory.removeByHistoryId(imphistoryid)
                        msg = u'<{}>下载付费简历总数:0'.format(
                            SiteConfig.getSiteNameById(siteid))
                        task.sync_status = 20
                        task.error_message = ''
                        task.process_time = datetime.today()
                        task.save()
                        logger.info(msg)
Exemplo n.º 3
0
def DownResume(checkstatservice, **kwargs):
    data = kwargs.copy()
    taskid = data['taskid']
    companyid = data['companyid']
    siteid = data['siteid']
    username = data['username']
    resumeid = data['resumeid']
    postdate = data['postdate']
    # 强制刷新简历(用於付费简历下载)
    force = data.get('force', False)
    #
    sitename = SiteConfig.getSiteNameById(siteid)
    importkey = Conf.RESUME_IMPORT_HKEY % taskid
    try:
        try:
            # 简历更新度验证(投递日期)
            if not force:
                if not ResumeBase.isNew(companyid, siteid, resumeid, postdate):
                    # 未更新的简历将会被忽略
                    logger.debug(u'<{}>简历<{}, {}>重复下载!'.format(
                        sitename, username, resumeid))
                    ResumeRedisCli.hincrby(importkey, 'ignore')
                    return
            try:
                handler = SiteConfig.GetTaskHandler(companyid, siteid, taskid)
                logger.info(u'正在下载<{}>简历<{}, {}>'.format(
                    sitename, username, resumeid))
                handler.resume_down(data)
                if handler.status == HANDLE_STATUS.SUCCESS:
                    logger.info(handler.message)
                    dtc. async ('zpb.service.resumeservice.ParseResume',
                                checkstatservice, **data),
                elif handler.status == HANDLE_STATUS.AGAIN:
                    logger.info(u'<{}>简历<{}, {}>需要重新下载'.format(
                        sitename, username, resumeid))
                    data['retry'] = data.get('retry', 0) + 1
                    dtc. async ('zpb.service.resumeservice.DownResume',
                                checkstatservice, **data),
                else:
                    ResumeRedisCli.hincrby(importkey, 'failure')
                    logger.error(handler.message)
            except BaseError as e:
                pass
        except BaseException as e:
            dtc. async ('zpb.service.resumeservice.DownResume',
                        checkstatservice, **data),
            logger.error(u'<{}>简历<{}, {}>下载异常,原因:{}'.format(
                sitename, username, resumeid, e))
    finally:
        dtc. async (checkstatservice, taskid)
Exemplo n.º 4
0
 def get(self):
     ret = {'status': 1, 'message': ''}
     try:
         company_id = str2int(self.get_argument('company_id', ''))
         site_id = str2int(self.get_argument('site_id', ''))
         if not (company_id and site_id):
             raise InvalidParamError(u'提交参数错误!')
         try:
             handler = SiteConfig.GetTaskHandler(company_id, site_id, None)
             try:
                 # 开始登陆
                 handler.login()
                 # 反馈结果
                 if handler.status == HANDLE_STATUS.SUCCESS:
                     ret['status'] = 100
                     # 增加201轮询指令
                     DBTask.newSchedule(company_id, site_id)
                 else:
                     ret['message'] = handler.message
             except BaseException as e:
                 raise UnHandleRuntimeError(e)
                 logger.error(u'Web服务请求异常,原因:{}'.format(e))
         except BaseError as e:
             ret['message'] = e.message
     finally:
         logger.debug(ret)
         self.write(json.dumps(ret))
Exemplo n.º 5
0
def DoInfo(companyid, siteid, taskid):
    try:
        handler = SiteConfig.GetTaskHandler(companyid, siteid, taskid)
        try:
            handler.info()
        except BaseException as e:
            raise UnHandleRuntimeError(e)
    except BaseError as e:
        pass
Exemplo n.º 6
0
 def queryAndCreate(cls, session, companyid, siteid, websiteresumeid, applytime):
     try:
         if companyid and websiteresumeid:
             # 来源于网站
             if siteid:
                 rm = session.query(ResumeBase).filter(
                     and_(
                         ResumeBase.company_id == companyid,
                         ResumeBase.from_site_id == siteid,
                         ResumeBase.from_site_code == websiteresumeid
                         )).first()
             # 来源于邮件
             else:
                 rm = session.query(ResumeBase).filter(
                     and_(
                         ResumeBase.company_id == companyid,
                         ResumeBase.from_site_code == websiteresumeid
                         )).first()
         # 来源于邮件且为手动简历(非系统生成)需要进一步依据简历内容过滤
         else:
             rm = None
         if not rm:
             # 新增简历
             rm = ResumeBase()
             rm.resume_code = uuid()
             rm.company_id = companyid
             rm.from_site_id = siteid
             rm.from_site_code = websiteresumeid
             rm.apply_time = str2date(applytime)
             rm.is_new = 'T'
             rm.create_user = '******'
             rm.create_time = datetime.today()
             # 新增resume_memo
             rmm = ResumeMemo(rm.resume_code)
             rmm.memo_content = u'来源于[{}]'.format(SiteConfig.getSiteNameById(siteid))
             session.add(rmm)
             return (True, rm)
         else:
             # 简历刷新
             if str2date(rm.apply_time, '%Y-%m-%d') < str2date(applytime):
                 rm.apply_time = str2date(applytime)
                 # 删除历史附加信息
                 session.query(ResumeExtend).filter(ResumeExtend.resume_code==rm.resume_code).delete()
                 session.query(ResumeEdu).filter(ResumeEdu.resume_code==rm.resume_code).delete()
                 session.query(ResumeEnglish).filter(ResumeEnglish.resume_code==rm.resume_code).delete()
                 session.query(ResumeExp).filter(ResumeExp.resume_code==rm.resume_code).delete()
                 session.query(ResumeIT).filter(ResumeIT.resume_code==rm.resume_code).delete()
                 session.query(ResumeLang).filter(ResumeLang.resume_code==rm.resume_code).delete()
                 session.query(ResumeProject).filter(ResumeProject.resume_code==rm.resume_code).delete()
                 session.query(ResumeTrain).filter(ResumeTrain.resume_code==rm.resume_code).delete()
                 return (True, rm)
             else:
                 return (False, rm)
     except BaseException as e:
         raise DBOperateError(currentFuncName(cls), e)
Exemplo n.º 7
0
def DoResumeSearcher(companyid, siteid, taskid, searcherid, **kwargs):
    try:
        handler = SiteConfig.GetTaskHandler(companyid, siteid, taskid)
        ResumeSearcher.updateImportTimeBySearcherId(searcherid)
        if handler.bind.check_status in [0, 50]:
            handler.resume_search(searcherid)
        else:
            handler.message = u'绑定账号登录失败'
        logger.info(handler.message)
    except BaseError:
        pass
Exemplo n.º 8
0
 def _uuid(self):
     uid = md5('{}-{}-{}-{}'.format(self.company_id, self.sync_id, self.resume_code, self.__class__.__name__))
     uname = u'<{}>简历付费下载'.format(SiteConfig.getSiteNameById(self.site_id))
     task = {
         'id': uid,
         'name': uname,
         'func': 'zpb.service.handleservice.DoResumePayDown',
         'args': (self.company_id, self.site_id, self.sync_id, self.from_site_code, self.own_pay, uid),
         'kwargs': {'priority': 1}
     }
     return task
Exemplo n.º 9
0
 def post(self):
     ret = {'status': 1, 'message': ''}
     try:
         site_id = str2int(self.get_argument('site_id', ''))
         member_name = self.get_argument('member_name', '')
         login_name = self.get_argument('login_name', '')
         login_pswd = self.get_argument('login_pswd', '')
         # 中文解码
         member_name = unquote(member_name.encode('gbk'))
         login_name = unquote(login_name.encode('gbk'))
         #
         session = self.get_argument('sessionid', '')
         try:
             if not session:
                 raise InvalidParamError(u'非法的请求!')
             if not (site_id and login_name and login_pswd):
                 raise InvalidParamError(u'非法的请求!')
             messages = decryptBindPasswd('zpb', session).split(':')
             if len(messages) != 2:
                 raise InvalidParamError(u'非法的请求!')
             companyid = messages[0]
             handler = SiteConfig.GetTaskHandler(0, site_id, None)
             # 登录密码解密
             password = decryptBindPasswd(login_name, login_pswd)
             if not password:
                 raise InvalidParamError(u'登录账号或密码错误!')
             try:
                 # 开始登陆
                 (res,
                  message) = handler.innerlogin(member_name, login_name,
                                                password)
                 # 反馈结果
                 if res:
                     if Bind.newAndSave(companyid, site_id, member_name,
                                        login_name, login_pswd):
                         ret['status'] = 0
                         ret['message'] = u'账号绑定成功!'
                     else:
                         ret['status'] = 0
                         ret['message'] = u'账号已绑定!'
                     DBTask.newSchedule(companyid, site_id)
                 else:
                     ret['message'] = message
             except BaseException as e:
                 raise UnHandleRuntimeError(e)
                 logger.error(u'Web服务请求异常,原因:{}'.format(e))
         except BaseError as e:
             ret['message'] = e.message
     finally:
         logger.debug(ret)
         self.write(json.dumps(ret))
Exemplo n.º 10
0
def Do20(companyid, siteid, syncid, taskid, **kwargs):
    task = DBTask.queryWithId(syncid)
    try:
        handler = SiteConfig.GetTaskHandler(companyid, siteid, taskid)
        # 账号已解除绑定
        if handler.bind.is_valid != 'T':
            DBTask.newSchedule(companyid, siteid, False)
            raise CompanyAccountUnBindError(companyid, siteid, u'账号已解除绑定')
        # 账号未验证通过
        if handler.bind.check_status == 10:
            raise CompanyAccountInvalidError(companyid, siteid, u'账号登录失败')
        try:
            handler.position_import()
            if HANDLE_STATUS.SUCCESS == handler.status:
                task.sync_status = 2000
                task.succ_num += 1
                task.log_info = handler.message
                # 账号绑定
                handler.bind.check_status = 50
                handler.bind.login_result = '登录成功'
                handler.bind.last_succ_time = datetime.today()
                handler.bind.save()
                # 下发其它异步任务
                infouid = md5(taskid + 'info')
                dtc. async ('zpb.service.handleservice.DoInfo',
                            *(companyid, siteid, infouid),
                            uid=infouid)
                resuid = md5(taskid + '201')
                dtc. async ('zpb.service.handleservice.Do201',
                            *(companyid, siteid, syncid, resuid),
                            uid=resuid)
                logger.info(handler.message)
            elif HANDLE_STATUS.AGAIN == handler.status:
                task.sync_status = 11
                task.fail_num += 1
                task.log_info = handler.message
                logger.error(handler.message)
            else:
                task.sync_status = 10
                task.fail_num += 1
                task.log_info = handler.message
                logger.error(handler.message)
        except BaseException as e:
            raise UnHandleRuntimeError(e)
    except BaseError as e:
        task.sync_status = 10
        task.fail_num += 1
        task.log_info = e.message
    task.save()
Exemplo n.º 11
0
def CheckResumeSearchStat(taskid):
    key = Conf.RESUME_IMPORT_HKEY % taskid
    stat = ResumeRedisCli.hgetall(key)
    if stat:
        # finish
        finish = int(stat.get('finish', '0'))
        if finish:
            # 统计信息
            total = int(stat['total'])
            grab = int(stat['grab'])
            succ = int(stat['success'])
            ignore = int(stat['ignore'])
            fail = int(stat['failure'])
            # 来源信息
            siteid = int(stat['siteid'])
            importid = stat['importid']
            companyid = int(stat['companyid'])
            imphistoryid = int(stat['imphistoryid'])
            #
            if total > 0 and total <= succ + ignore + fail:
                if total <= succ + ignore + fail:
                    if ResumeRedisCli.delete(key):
                        imp = ImpHistory.queryByHistoryId(imphistoryid)
                        if imp:
                            imp.succ_num = succ
                            imp.fail_num = fail
                            imp.end_time = datetime.today()
                            imp.proc_status = 1
                            if imp.succ_num == 0:
                                imp.is_valid = 'F'
                            imp.save()
                        # 更新bind简历最后导入时间(siteid取自key,task中的site_id可能=0)
                        AuthService().updateBindImportTimeByCompanyIdAndSiteId(
                            companyid, siteid)
                        # 回写任务状态
                        msg = u'<{}>简历总数<{}>,下载数<{}>,成功数<{}>,重复数<{}>,失败数<{}>.'.format(
                            SiteConfig.getSiteNameById(siteid), total, grab,
                            succ, ignore, fail)
                        logger.info(msg)
            elif total == 0:
                if ResumeRedisCli.delete(key):
                    ImpHistory.removeByHistoryId(imphistoryid)
                    # 更新bind简历最后导入时间(siteid取自key,task中的site_id可能=0)
                    AuthService().updateBindImportTimeByCompanyIdAndSiteId(
                        companyid, siteid)
Exemplo n.º 12
0
 def _uuid(self, siteid):
     uid = md5('{}-{}-{}-{}'.format(self.company_id, siteid, self.sync_id,
                                    self.__class__.__name__))
     uname = u'<{}>任务指令中心:{}'.format(SiteConfig.getSiteNameById(siteid),
                                     self.command_type),
     task = {
         'id': uid,
         'name': uname,
         'func': 'zpb.service.handleservice.Do{}'.format(self.command_type),
         # args: 必要条件
         'args': (self.company_id, siteid, self.sync_id, uid),
         # kwargs: 非必要条件
         'kwargs': {
             'jobid': self.job_id,
             'otherid': self.other_id,
             'priority': self.proc_priority
         }
     }
     return task
Exemplo n.º 13
0
 def new(companyid, siteid, importid, importtype=4):
     imp = ImpHistory()
     imp.company_id = companyid
     # 此处默认(4),resumeservice手工导入修改该数据
     imp.import_type = importtype  # 招聘平台导入
     if imp.import_type == 4:
         imp.src_memo = SiteConfig.getSiteNameWithId(siteid)
     else:
         imp.src_memo = ''
     imp.import_id = importid
     imp.succ_num = 0
     imp.fail_num = 0
     imp.start_time = datetime.today()
     # 初始状态处理中
     imp.proc_status = 0
     imp.is_valid = 'T'
     imp.create_user = '******'
     imp.create_time = datetime.today()
     return imp
Exemplo n.º 14
0
 def save(self):
     """
     职位保存或更新,同时更新职位属性与职位标签
     """
     session = DBInstance.session
     try:
         session.add(self)
         if self.job_id:
             session.query(JobProperty).filter(
                 JobProperty.job_id == self.job_id).delete()
         else:
             session.flush()
             # 增加同步分发记录
             dist = JobSyncDistribute.new(self.job_id, self.from_site_id,
                                          self.company_id)
             dist.sync_status = 20
             dist.third_job_code = self.from_site_code
             dist.sync_succ_num = 1
             session.add(dist)
             # 增加职位新增日志
             jmm = JobMemo(self.job_id)
             jmm.memo_content = u'来源于[{}]'.format(
                 SiteConfig.getSiteNameById(self.from_site_id))
             session.add(jmm)
         # 增加标签
         for item in self.tags:
             tag = SysTag.queryByTagNameWithCompanyid(item, self.company_id)
             if not tag:
                 tag = SysTag.new(item, self.company_id)
                 session.add(tag)
                 session.flush()
             prop = JobProperty.new(self.job_id, tag.tag_id, 9999)
             session.add(prop)
         for tagid in self.props:
             prop = JobProperty.new(self.job_id, tagid)
             session.add(prop)
         session.commit()
         return True
     except BaseException as e:
         session.rollback()
         raise DBOperateError(currentFuncName(self), e)
     finally:
         session.close()
Exemplo n.º 15
0
def PackPositionDown(grab, job):
    try:
        if grab.siteid == 1:
            wyjob.pack_position(grab, job)
        elif grab.siteid == 2:
            rd2.pack_position(grab, job)
        elif grab.siteid == 3:
            lag.pack_position(grab, job)
        elif grab.siteid == 4:
            cjol.pack_position(grab, job)
        elif grab.siteid == 5:
            wuba.pack_position(grab, job)
        elif grab.siteid == 6:
            ganj.pack_position(grab, job)
        elif grab.siteid == 7:
            liep.pack_position(grab, job)
        return True
    except BaseException as e:
        logger.error(u'<{}>下载职位<{}>失败,原因:<{}>'.format(SiteConfig.getSiteNameById(grab.siteid), grab.jobid, e))
        return True
Exemplo n.º 16
0
def Do201(companyid, siteid, syncid, taskid, **kwargs):
    task = DBTask.queryWithId(syncid)
    try:
        handler = SiteConfig.GetTaskHandler(companyid, siteid, taskid)
        # 账号已解除绑定
        if handler.bind.is_valid != 'T':
            DBTask.newSchedule(companyid, siteid, False)
            raise CompanyAccountUnBindError(companyid, siteid, u'账号已解除绑定')
        # 账号未验证通过
        if handler.bind.check_status == 10:
            raise CompanyAccountInvalidError(companyid, siteid, u'账号登录失败')
        try:
            handler.resume_import(syncid)
        except BaseException as e:
            raise UnHandleRuntimeError(e)
        if HANDLE_STATUS.SUCCESS == handler.status:
            task.succ_num += 1
            task.log_info = handler.message
            task.sync_status = 20
            #
            dtc. async ('zpb.service.handleservice.DoInfo',
                        *(companyid, siteid, taskid))
            logger.info(handler.message)
        else:
            task.fail_num += 1
            task.log_info = handler.message
            if HANDLE_STATUS.AGAIN == handler.status:
                task.sync_status = 11
            else:
                task.sync_status = 10
            logger.error(handler.message)
    except BaseError as e:
        task.sync_status = 10
        task.fail_num += 1
        task.log_info = e.message
    task.save()
Exemplo n.º 17
0
def ParseLocalResume(companyid, taskid, importid):
    row = ImpLocalFile.queryByImportId(importid)
    if row:
        sitename = SiteConfig.getSiteNameById(row.from_site_id)
        logger.info(u'开始解析<{}>的本地简历'.format(sitename))
        row.proc_status = 10
        imp = ImpHistory.new(row.company_id, row.from_site_id, row.import_id,
                             row.input_type)
        if row.input_type == 1:
            imp.src_memo = row.user_file_name
        if not imp.save():
            return
        # 异常信息提示
        log_msg = u''
        try:
            if row.input_type == 1:
                log_msg = u'简历文件<{}>解析'.format(row.user_file_name)
                # 数据库存储类型为hex编码,此处进行解码
                content = base64.b64encode(row.file_content)
                ext = os.path.splitext(row.user_file_name)[-1]
                ret = _doResumeParseByFile(content, ext)
            else:
                log_msg = u'简历文本解析'
                content = row.input_content
                ret = _doResumeParseByString(content)
            if ret:
                js = json.loads(ret)
                if js['Type'] > 0 and js['Name']:
                    js['companyid'] = row.company_id
                    js['siteid'] = row.from_site_id
                    if js['WebSiteResumeID']:
                        js['websiteresumeid'] = js['WebSiteResumeID']
                    else:
                        js['websiteresumeid'] = 'Local{0}'.format(
                            row.import_id)
                    js['jobid'] = ''
                    js['source'] = 0
                    js['apply_job_id'] = row.apply_job_id
                    js['apply_time'] = datetime2str(datetime.today())
                    (res, message, new) = AssembelResumeByJson(js)
                    if res:
                        row.resume_code = message
                        row.proc_status = 20
                        # 保存简历历史详细记录
                        if ImpHistoryResume.newAndSave(imp.history_id,
                                                       row.company_id,
                                                       message):
                            # 保存简历历史记录
                            imp.succ_num = 1
                            imp.proc_status = 1
                            message = u'{}成功'.format(log_msg)
                            logger.info(message)
                        else:
                            message = u'数据存储失败'
                            logger.error('{}失败,{}'.format(log_msg, message))
                            imp.fail_num = 1
                            imp.proc_status = 2
                            imp.fail_reason = message
                    else:
                        logger.error('{}失败,{}'.format(log_msg, message))
                        imp.fail_num = 1
                        imp.proc_status = 2
                        imp.fail_reason = message
                else:
                    message = u'简历内容为空'
                    logger.error('{}失败,{}'.format(log_msg, message))
                    imp.fail_num = 1
                    imp.proc_status = 2
                    imp.fail_reason = message
            else:
                message = u'解析结果为空'
                logger.error('{}失败,{}'.format(log_msg, message))
                imp.fail_num = 1
                imp.proc_status = 2
                imp.fail_reason = message
        except BaseException as e:
            message = u'{}异常,原因:{}'.format(log_msg, e)
            logger.error(message)
            imp.fail_num = 1
            imp.proc_status = 2
            imp.fail_reason = u'内部服务错误!'
        # 历史结果存储
        row.save()
        imp.end_time = datetime.today()
        imp.save()
Exemplo n.º 18
0
 def __str__(self):
     from zpb.business.siteconfig import SiteConfig
     return u'企业<{}>,招聘平台<{}>,错误码<{}>,原因<{}>'.format(
         self.company, SiteConfig.getSiteNameById(self.siteid), self.code,
         self.message)
Exemplo n.º 19
0
def Do101(companyid, siteid, syncid, taskid, **kwargs):
    task = DBTask.queryWithId(syncid)
    try:
        jobid = kwargs.pop('jobid', None)
        if not jobid:
            raise InvalidParamError(companyid, siteid, u'未指定发布职位编号')
        handler = SiteConfig.GetTaskHandler(companyid, siteid, taskid)
        # 账号已解除绑定
        if handler.bind.is_valid != 'T':
            DBTask.newSchedule(companyid, siteid, False)
            raise CompanyAccountUnBindError(companyid, siteid, u'账号已解除绑定')
        # 账号未验证通过
        if handler.bind.check_status == 10:
            raise CompanyAccountInvalidError(companyid, siteid, u'账号登录失败')
        # step 1
        dist = JobSyncDistribute.queryByJobIdAndCompanyIdWithSiteId(
            jobid, companyid, siteid)
        if not dist:
            raise JobNotDistributeError(companyid, siteid, u'未找到职位同步记录')
        try:
            if not dist.third_job_code:
                handler.position_add(jobid)
            else:
                handler.position_modify(jobid, dist.third_job_code,
                                        dist.last_sync_time)
            # step 2
            if HANDLE_STATUS.SUCCESS == handler.status:
                if hasattr(handler, 'thirdjobcode'):
                    dist.third_job_code = handler.thirdjobcode
                dist.sync_succ_num += 1
                dist.sync_status = 20
                dist.error_message = ''
                dist.last_sync_time = datetime.today()
                #
                BaseJob.updateSyncTimeByJobId(jobid)
                #
                dtc. async ('zpb.service.handleservice.DoInfo',
                            *(companyid, siteid, taskid))
            else:
                dist.sync_fail_num += 1
                dist.sync_status = 10
                dist.error_message = handler.message
            dist.save()
            # step 3
            jmm = JobMemo(jobid)
            if HANDLE_STATUS.SUCCESS == handler.status:
                jmm.memo_content = u'[{}]发布成功'.format(handler.name)
            else:
                jmm.memo_content = u'[{}]发布失败,{}'.format(
                    handler.name, handler.message)
            jmm.save()
            # step 4
            if HANDLE_STATUS.SUCCESS == handler.status:
                task.succ_num += 1
                task.log_info = handler.message
                task.sync_status = 20
                logger.info(handler.message)
            else:
                task.fail_num += 1
                task.log_info = handler.message
                if HANDLE_STATUS.AGAIN == handler.status:
                    task.sync_status = 11
                else:
                    task.sync_status = 10
                logger.error(handler.message)
        except BaseException as e:
            raise UnHandleRuntimeError(e)
    except BaseError as e:
        task.sync_status = 10
        task.fail_num += 1
        task.log_info = e.message
    task.save()
Exemplo n.º 20
0
def ParseResume(checkstatservice, **kwargs):
    data = kwargs.copy()
    taskid = data['taskid']
    companyid = data['companyid']
    siteid = data['siteid']
    jobid = data['jobid']
    source = data.get('source', 0)
    username = data['username']
    resumeid = data['resumeid']
    postdate = data['postdate']
    # 强制刷新简历(用於付费简历下载)
    force = data.get('force', False)
    # 简历与职位匹配度
    matching = data.get('matching', 0)
    #
    sitename = SiteConfig.getSiteNameById(siteid)
    importkey = Conf.RESUME_IMPORT_HKEY % taskid
    try:
        try:
            # 开始解析
            logger.info(u'正在解析<{}>简历<{}>, <{}>'.format(sitename, username,
                                                       resumeid))
            filepath = data['filepath']
            if os.path.isfile(filepath):
                # 用於文件备份
                # basename = os.path.basename(filepath)
                # dirname = os.path.dirname(filepath)
                ext = os.path.splitext(filepath)[-1]
                ret = _doResumeParseByFile(
                    base64.b64encode(open(filepath, 'rb').read()), ext)
                if ret:
                    js = json.loads(ret)
                    if js['Type'] == 0:
                        ResumeRedisCli.hincrby(importkey, 'failure')
                        logger.error(u'<{}>简历<{}, {}>解析失败,原因:{}'.format(
                            sitename, username, resumeid, js['Name']))
                        return
                    if not js['Name']:
                        ResumeRedisCli.hincrby(importkey, 'failure')
                        logger.error(
                            u'<{}>简历<{}, {}>解析失败,原因:文件不是一份完整的简历!'.format(
                                sitename, username, resumeid))
                        return
                    #
                    js['companyid'] = companyid
                    js['siteid'] = siteid
                    if siteid == 4:
                        if resumeid:
                            js['websiteresumeid'] = resumeid
                        elif js['WebSiteResumeID']:
                            js['websiteresumeid'] = js[
                                'WebSiteResumeID'].replace('J', '')
                        else:
                            js['websiteresumeid'] = ''
                    else:
                        js['websiteresumeid'] = resumeid if resumeid else js[
                            'WebSiteResumeID']
                    js['jobid'] = jobid
                    js['source'] = source
                    js['force'] = force
                    js['matching'] = matching
                    js['apply_job_id'] = 0
                    js['apply_time'] = postdate
                    (res, message, new) = AssembelResumeByJson(js)
                    if res:
                        logger.info(u'<{}>简历<{}, {}>解析成功!'.format(
                            sitename, username, resumeid))
                        # 简历存储
                        imphistoryid = ResumeRedisCli.hget(
                            importkey, 'imphistoryid')
                        # 简历刷新,不必新增
                        if new:
                            ResumeRedisCli.hincrby(importkey, 'success')
                            # 保存简历历史详细记录
                            if ImpHistoryResume.newAndSave(
                                    imphistoryid, companyid, message):
                                ImpHistory.incSuccessByHistoryId(imphistoryid)
                            else:
                                logger.error(u'<{}>简历<{}, {}>历史详情保存异常!'.format(
                                    sitename, username, resumeid))
                        else:
                            ResumeRedisCli.hincrby(importkey, 'ignore')
                    else:
                        ResumeRedisCli.hincrby(importkey, 'failure')
                        logger.error(u'<{}>简历<{}, {}>解析失败,原因:{}'.format(
                            sitename, username, resumeid, message))
                else:
                    ResumeRedisCli.hincrby(importkey, 'failure')
                    message = u'简历服务器解析简历返回结果异常,<{}><{}, {}>'.format(
                        sitename, username, resumeid)
                    logger.error(message)
            else:
                ResumeRedisCli.hincrby(importkey, 'failure')
                message = u'简历解析失败,磁盘文件<{}>不存在'.format(sitename, username,
                                                       resumeid)
                logger.error(message)
        except BaseException as e:
            dtc. async ('zpb.service.resumeservice.ParseResume',
                        checkstatservice, **data),
            logger.error(u'简历解析服务异常,message:{}'.format(e))
    finally:
        dtc. async (checkstatservice, taskid)