Ejemplo n.º 1
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))
Ejemplo n.º 2
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', '')
         session = self.get_argument('sessionid', '')
         # 中文解码
         member_name = unquote(member_name.encode('gbk'))
         login_name = unquote(login_name.encode('gbk'))
         #
         if session:
             if site_id and login_name:
                 messages = decryptBindPasswd('zpb', session).split(':')
                 if len(messages) == 2:
                     companyid = messages[0]
                     if Bind.unBind(companyid, site_id, member_name,
                                    login_name):
                         ret['status'] = 0
                         ret['message'] = u'账号解绑成功!'
                         DBTask.newSchedule(companyid, site_id, False)
                     else:
                         ret['message'] = u'账号解绑失败,账号尚未绑定!'
                 else:
                     ret['message'] = u'非法的请求!'
             else:
                 ret['message'] = u'非法的请求,提交参数不全!'
         else:
             ret['message'] = u'非法的请求!'
     finally:
         logger.debug(ret)
         self.write(json.dumps(ret))
Ejemplo n.º 3
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))
Ejemplo n.º 4
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()
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
def Do301(companyid, siteid, syncid, taskid, **kwargs):
    task = DBTask.queryWithId(syncid)
    try:
        otherid = kwargs.pop('otherid', None)
        if not otherid:
            raise InvalidParamError(companyid, siteid, u'未指定邮箱编号')
        from zpb.service.mailservice import DoMailSearcher
        DoMailSearcher(companyid, taskid, otherid, syncid)
        task.sync_status = 2010
    except BaseError as e:
        task.sync_status = 10
        task.fail_num += 1
        task.log_info = e.message
    task.save()
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
Archivo: app.py Proyecto: cash2one/ZPB
def dispatcher(event):
    def _async_task(tasks):
        # 分发异步任务
        for task in tasks:
            taskname = task.get('name', False)
            if taskname:
                logger.debug(u'dispatcher task named <{}>'.format(taskname))
            args = task.get('args', ())
            kwargs = task.get('kwargs', {})
            kwargs['uid'] = task['id']
            dtc. async (task['func'], *args, **kwargs)

    #
    name = current_process().name
    pid = current_process().pid
    logger.info('{} dispatch tasks at {}'.format(name, pid))
    while not event.is_set():
        try:
            # 任务指令中心
            task_set = DBTask.queryPending() or []
            _async_task(task_set)
            # 手动简历解析
            task_set = ImpLocalFile.queryPending() or []
            _async_task(task_set)
            # 付费简历下载
            task_set = ResSyncDistribute.queryPending() or []
            _async_task(task_set)
            # 邮件搜索定时任务
            task_set = EmailConf.queryPending() or []
            _async_task(task_set)
            # 简历搜索定时任务
            task_set = ResumeSearcher.queryPending() or []
            _async_task(task_set)
            # 关键词百科超链接
            task_set = HyperLink.queryPending() or []
            _async_task(task_set)
            #
            sleep(2)
        except BaseException as e:
            logger.error(e)
            break
    logger.info('{} stopped dispatch tasks'.format(name))
Ejemplo n.º 9
0
def CheckResumeImportStat(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 = DBTask.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()
                            # 更新bind简历最后导入时间(siteid取自key,task中的site_id可能=0)
                            AuthService(
                            ).updateBindImportTimeByCompanyIdAndSiteId(
                                companyid, siteid)
                            # 回写任务状态
                            msg = u'{}<{}>简历总数<{}>,下载数<{}>,成功数<{}>,重复数<{}>,失败数<{}>.'.format(
                                datetime.today(),
                                SiteConfig.getSiteNameById(siteid), total,
                                grab, succ, ignore, fail)
                            task.succ_num += 1
                            task.sync_status = 20
                            task.log_info = msg
                            task.save()
                            logger.info(msg)
                elif total == 0:
                    if ResumeRedisCli.delete(key):
                        ImpHistory.removeByHistoryId(imphistoryid)
                        # 更新bind简历最后导入时间(siteid取自key,task中的site_id可能=0)
                        AuthService().updateBindImportTimeByCompanyIdAndSiteId(
                            companyid, siteid)
                        if task.sync_status not in [10, 11]:
                            task.sync_status = 20
                        msg = u'{}<{}>简历总数:0'.format(
                            datetime.today(),
                            SiteConfig.getSiteNameById(siteid))
                        task.succ_num += 1
                        task.sync_status = 20
                        task.log_info = msg
                        task.save()
                        logger.info(msg)
Ejemplo n.º 10
0
def CheckEmailImportStat(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 = stat['siteid']
            importid = stat['importid']
            companyid = stat['companyid']
            imphistoryid = int(stat['imphistoryid'])
            syncid = int(stat.get('syncid', None))
            #
            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()
                        # 更新邮箱信息
                        EmailConf.updateImportTimeAndNumberByImportId(
                            importid, succ)
                        # 回写任务状态
                        msg = u'<{}>邮箱简历总数<{}>,下载数<{}>,成功数<{}>,重复数<{}>,失败数<{}>.'.format(
                            siteid, total, grab, succ, ignore, fail)
                        logger.info(msg)
                        # 任务状态回写
                        if syncid:
                            task = DBTask.queryWithId(syncid)
                            if task:
                                task.succ_num += 1
                                task.sync_status = 20
                                task.log_info = msg
                                task.save()
            elif total == 0:
                if ResumeRedisCli.delete(key):
                    ImpHistory.removeByHistoryId(imphistoryid)
                    # 更新邮箱信息
                    EmailConf.updateImportTimeAndNumberByImportId(importid, 0)
                    msg = u'<{}>邮箱简历总数:0'.format(siteid)
                    logger.info(msg)
                    # 任务状态回写
                    if syncid:
                        task = DBTask.queryWithId(syncid)
                        if task:
                            task.succ_num += 1
                            task.sync_status = 20
                            task.log_info = msg
                            task.save()
Ejemplo n.º 11
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()