示例#1
0
    def getTask(peer_id):
        # TaskManager.cancelLongRunningTasks()
        job = JobController.getJobWithFreeTask()

        if not job:
            return 0

        task = JobController.getTask(job, peer_id)

        return task
示例#2
0
    def getTask(peer_id):
        # TaskManager.cancelLongRunningTasks()
        job = JobController.getJobWithFreeTask()

        if not job:
            return 0

        task = JobController.getTask(job, peer_id)

        return task
示例#3
0
文件: task.py 项目: JelteF/bottor
    def cancelTask(task_id):
        from app.controllers.job import JobController
        task = TaskController.get(task_id)
        job = task.job

        cancelCnt = 0

        for i in range(task.nRows):
            for j in range(task.nCols):
                if JobController.getState(job, task.startRow + i,
                        task.startCol +j) != Constants.STATE_DONE:
                    JobController.changeState(job, Constants.STATE_NONE,
                        task.startRow + i, task.startCol + j)
                    cancelCnt += 1

        job.running -= cancelCnt
        job.free += cancelCnt
        TaskController.delete(task)
示例#4
0
文件: task.py 项目: JelteF/bottor
    def cancelTask(task_id):
        from app.controllers.job import JobController
        task = TaskController.get(task_id)
        job = task.job

        cancelCnt = 0

        for i in range(task.nRows):
            for j in range(task.nCols):
                if JobController.getState(
                        job, task.startRow + i,
                        task.startCol + j) != Constants.STATE_DONE:
                    JobController.changeState(job, Constants.STATE_NONE,
                                              task.startRow + i,
                                              task.startCol + j)
                    cancelCnt += 1

        job.running -= cancelCnt
        job.free += cancelCnt
        TaskController.delete(task)
示例#5
0
    def testShizzle(self):
        matrixA = "sample_matrices/A20"
        matrixB = "sample_matrices/B20"
        job = JobController.create(matrixA, matrixB)
        job2 = JobController.create(matrixA, matrixB)

        task1 = TaskManager.getTask(1)
        assert task1

        task2 = TaskManager.getTask(1)
        assert task2

        array = Matrix.matrices[job.getTaskMatrix()]
        MatrixController.writeArrayToFile(array, "result_matrices/test_job_cancelling_1")
        time.sleep(2)
        task3 = TaskManager.getTask(1)
        assert task3
        task4 = TaskManager.getTask(1)
        MatrixController.writeArrayToFile(array, "result_matrices/test_job_cancelling_2")
        TaskManager.cancelLongRunningTasks()
        MatrixController.writeArrayToFile(array, "result_matrices/test_job_cancelling_3")
示例#6
0
def generate_job_data(job, company_id):
    """生成职位数据"""
    department, description, keywords = requests_job_detail_data(
        job['positionId'])
    job_id = job['positionId']
    city_id = 0 if 'city' not in job else CityController.get_city_id_by_name(
        job['city'])
    title = job['positionName']
    work_year = filter_http_tag(job['workYear'])
    if work_year not in WORK_YEARS_REQUEST_DICT:
        logger.error(work_year + 'not in WORK_YEAR_DICT')
    work_year = WORK_YEARS_REQUEST_DICT[
        work_year] if work_year in WORK_YEARS_REQUEST_DICT else WORK_YEARS_REQUEST_DICT[
            'unknown']
    salary = job['salary']
    education = EDUCATION_REQUEST_DICT[job['education']]
    department = department
    description = description
    advantage = job['positionAdvantage'] if 'positionAdvantage' in job else ''
    job_nature = JOB_NATURE_DICT[job['jobNature']]
    created_at = job_date2timestamp(job['createTime'])

    JobController.add(id=job_id,
                      company_id=company_id,
                      title=title,
                      work_year=work_year,
                      city_id=city_id,
                      salary=salary,
                      education=education,
                      department=department,
                      description=description,
                      advantage=advantage,
                      job_nature=job_nature,
                      created_at=created_at)
    for keyword in keywords:
        keyword_id = KeywordController.get_keyword_id_by_name(keyword)
        JobKeywordController.add(job_id, keyword_id, city_id)
示例#7
0
def update_job_data(company_id):
    """更新职位数据"""
    response = request_job_json(company_id=company_id, page_no=1)
    # 计算该公司职位的页数
    page_count = int(
        ceil(
            int(response['content']['data']['page']['totalCount']) /
            int(response['content']['data']['page']['pageSize'])))
    for page_no in range(1, page_count + 1):
        json_result = request_job_json(company_id=company_id, page_no=page_no)
        jobs = json_result['content']['data']['page']['result']
        for job in jobs:
            job_id = job['positionId']
            if JobController.count(id=int(job_id)) == 0:
                generate_job_data(job, company_id)
示例#8
0
    def testShizzle(self):
        matrixA = "sample_matrices/A20"
        matrixB = "sample_matrices/B20"
        job = JobController.create(matrixA, matrixB)
        job2 = JobController.create(matrixA, matrixB)

        task1 = TaskManager.getTask(1)
        assert task1

        task2 = TaskManager.getTask(1)
        assert task2

        array = Matrix.matrices[job.getTaskMatrix()]
        MatrixController.writeArrayToFile(
            array, "result_matrices/test_job_cancelling_1")
        time.sleep(2)
        task3 = TaskManager.getTask(1)
        assert task3
        task4 = TaskManager.getTask(1)
        MatrixController.writeArrayToFile(
            array, "result_matrices/test_job_cancelling_2")
        TaskManager.cancelLongRunningTasks()
        MatrixController.writeArrayToFile(
            array, "result_matrices/test_job_cancelling_3")
示例#9
0
    def get(self):
        keyword_name = self.get_argument('keyword', 'python')
        keyword = KeywordController.get(name=keyword_name)
        if not keyword:
            self.write_error(404)
            return

        (keyword_jobs_count, educations_request_counter,
         finance_stage_distribution, city_jobs_counter, salary_distribution,
         work_years_request_analyze) = JobController.get_jobs_statistics(
             keyword_id=keyword.id)

        self.render("keyword.html",
                    keyword=keyword_name,
                    keyword_jobs_count=keyword_jobs_count,
                    educations_request_counter=educations_request_counter,
                    finance_stage_distribution=finance_stage_distribution,
                    city_jobs_counter=city_jobs_counter,
                    salary_distribution=salary_distribution,
                    work_years_request_analyze=work_years_request_analyze)
示例#10
0
    def get(self):
        # 统计访问人数  incr() 操作线程安全
        redis_instance.incr(constants.REDIS_VISITED_PEOPLES_COUNT_KEY)
        keyword_name = self.get_argument('keyword', 'python')
        keyword = KeywordController.get(name=keyword_name)
        if not keyword:
            self.write_error(404)
            return

        (keyword_jobs_count, educations_request_counter,
         finance_stage_distribution, city_jobs_counter, salary_distribution,
         work_years_request_analyze) = JobController.get_jobs_statistics(
             keyword_id=keyword.id)

        self.render("keyword.html",
                    keyword=keyword_name,
                    keyword_jobs_count=keyword_jobs_count,
                    educations_request_counter=educations_request_counter,
                    finance_stage_distribution=finance_stage_distribution,
                    city_jobs_counter=city_jobs_counter,
                    salary_distribution=salary_distribution,
                    work_years_request_analyze=work_years_request_analyze)