Repository: ansible/awx
File: awx/main/scheduler/dependency_graph.py (Python)

Code before:

    def get_now(self):
        return tz_now()

    def mark_system_job(self):
        self.data[self.SYSTEM_JOB] = False

    def mark_project_update(self, job):
        self.data[self.PROJECT_UPDATES][job.project_id] = False

    def mark_inventory_update(self, inventory_id):
        self.data[self.INVENTORY_UPDATES][inventory_id] = False

    def mark_inventory_source_update(self, inventory_source_id):
        self.data[self.INVENTORY_SOURCE_UPDATES][inventory_source_id] = False

    def mark_job_template_job(self, job):
        self.data[self.JOB_INVENTORY_IDS][job.inventory_id] = False
        self.data[self.JOB_PROJECT_IDS][job.project_id] = False
        self.data[self.JOB_TEMPLATE_JOBS][job.job_template_id] = False

    def mark_workflow_job(self, job):
        self.data[self.WORKFLOW_JOB_TEMPLATES_JOBS][job.workflow_job_template_id] = False

    def can_project_update_run(self, job):
        return self.data[self.PROJECT_UPDATES].get(job.project_id, True)

    def can_inventory_update_run(self, job):
        return self.data[self.JOB_INVENTORY_IDS].get(job.inventory_source.inventory_id, True) and \
            self.data[self.INVENTORY_SOURCE_UPDATES].get(job.inventory_source_id, True)

    def can_job_run(self, job):
        if self.data[self.PROJECT_UPDATES].get(job.project_id, True) is True and \
                self.data[self.INVENTORY_UPDATES].get(job.inventory_id, True) is True:
            if job.allow_simultaneous is False:
                return self.data[self.JOB_TEMPLATE_JOBS].get(job.job_template_id, True)
            else:
                return True
        return False

    def can_workflow_job_run(self, job):
        if job.allow_simultaneous:
            return True
        return self.data[self.WORKFLOW_JOB_TEMPLATES_JOBS].get(job.workflow_job_template_id, True)

    def can_system_job_run(self):
        return self.data[self.SYSTEM_JOB]

    def can_ad_hoc_command_run(self, job):
        return self.data[self.INVENTORY_UPDATES].get(job.inventory_id, True)


Review comment (suggestion):
just to clarify, I think we should remove _all_ references to the variable `JOB_PROJECT_IDS` because it's no longer needed.

Code after:

    def mark_system_job(self):
        self.data[self.SYSTEM_JOB] = False

    def mark_project_update(self, job):
        self.data[self.PROJECT_UPDATES][job.project_id] = False

    def mark_inventory_update(self, inventory_id):
        self.data[self.INVENTORY_UPDATES][inventory_id] = False

    def mark_inventory_source_update(self, inventory_source_id):
        self.data[self.INVENTORY_SOURCE_UPDATES][inventory_source_id] = False

    def mark_job_template_job(self, job):
        self.data[self.JOB_INVENTORY_IDS][job.inventory_id] = False
        self.data[self.JOB_TEMPLATE_JOBS][job.job_template_id] = False

    def mark_workflow_job(self, job):
        self.data[self.WORKFLOW_JOB_TEMPLATES_JOBS][job.workflow_job_template_id] = False

    def can_project_update_run(self, job):
        return self.data[self.PROJECT_UPDATES].get(job.project_id, True)

    def can_inventory_update_run(self, job):
        return self.data[self.JOB_INVENTORY_IDS].get(job.inventory_source.inventory_id, True) and \
            self.data[self.INVENTORY_SOURCE_UPDATES].get(job.inventory_source_id, True)

    def can_job_run(self, job):
        if self.data[self.PROJECT_UPDATES].get(job.project_id, True) is True and \
                self.data[self.INVENTORY_UPDATES].get(job.inventory_id, True) is True:
            if job.allow_simultaneous is False:
                return self.data[self.JOB_TEMPLATE_JOBS].get(job.job_template_id, True)
            else:
                return True
        return False

    def can_workflow_job_run(self, job):
        if job.allow_simultaneous:
            return True
        return self.data[self.WORKFLOW_JOB_TEMPLATES_JOBS].get(job.workflow_job_template_id, True)

    def can_system_job_run(self):
        return self.data[self.SYSTEM_JOB]

    def can_ad_hoc_command_run(self, job):
        return self.data[self.INVENTORY_UPDATES].get(job.inventory_id, True)

    def is_job_blocked(self, job):
        if type(job) is ProjectUpdate:
            return not self.can_project_update_run(job)
        elif type(job) is InventoryUpdate: