How to use libmozevent - 10 common examples

To help you get started, we’ve selected a few libmozevent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / code-review / events / code_review_events / workflow.py View on Github external
async def process_build(self, build):
        """
        Code review workflow to load all necessary information from Phabricator builds
        received from the webserver
        """
        assert build is not None, "Invalid payload"
        assert isinstance(build, PhabricatorBuild)

        # Update its state
        self.update_state(build)

        if build.state == PhabricatorBuildState.Public:

            # Check if the author is not blacklisted
            if self.is_blacklisted(build.revision):
                return

            # When the build is public, load needed details
            try:
                self.load_patches_stack(build)
                logger.info("Loaded stack of patches", build=str(build))
            except Exception as e:
                logger.warning(
                    "Failed to load build details", build=str(build), error=str(e)
                )
                return

            # Then send the build toward next stage
github mozilla / code-review / events / code_review_events / bugbug_utils.py View on Github external
async def start_risk_analysis(self, build: PhabricatorBuild):
        """
        Run risk analysis by triggering a Taskcluster hook
        """
        assert build.state == PhabricatorBuildState.Public
        try:
            if not self.should_run_risk_analysis(build):
                return

            task = self.community_tc["hooks"].triggerHook(
                "project-relman",
                "bugbug-classify-patch",
                {
                    "PHABRICATOR_DEPLOYMENT": self.phabricator_deployment,
                    "DIFF_ID": build.diff_id,
                },
            )
            task_id = task["status"]["taskId"]
            logger.info("Triggered a new risk analysis task", id=task_id)

            # Send task to monitoring
github mozilla / code-review / events / code_review_events / workflow.py View on Github external
logger.warning(
                    "Failed to load build details", build=str(build), error=str(e)
                )
                return

            # Then send the build toward next stage
            logger.info("Send build to Mercurial", build=str(build))
            await self.bus.send(QUEUE_MERCURIAL, build)

            # Report public bug as 'working' (in progress)
            await self.bus.send(QUEUE_PHABRICATOR_RESULTS, ("work", build, {}))

            # Send to bugbug workflow
            await self.bus.send(QUEUE_BUGBUG, build)

        elif build.state == PhabricatorBuildState.Queued:
            # Requeue when nothing changed for now
            await self.bus.send(QUEUE_WEB_BUILDS, build)
github mozilla / code-review / events / code_review_events / bugbug_utils.py View on Github external
async def start_test_selection(self, build: PhabricatorBuild, revision: str):
        """
        Run test selection by triggering a Taskcluster hook
        """
        assert build.state == PhabricatorBuildState.Public
        try:
            if not self.should_run_test_selection(build):
                return

            task = self.community_tc["hooks"].triggerHook(
                "project-relman",
                "bugbug-test-select",
                {
                    "PHABRICATOR_DEPLOYMENT": self.phabricator_deployment,
                    "DIFF_ID": build.diff_id,
                    "RUNNABLE_JOBS": self.index_service.buildUrl(
                        "findArtifactFromTask",
                        f"gecko.v2.try.revision.{revision}.firefox.decision",
                        "public/runnable-jobs.json",
                    ),
                },
github mozilla / code-review / events / code_review_events / workflow.py View on Github external
self.workflow.register(self.bus)

            # Build mercurial worker and queue
            self.mercurial = MercurialWorker(
                QUEUE_MERCURIAL,
                QUEUE_MERCURIAL_APPLIED,
                repositories=self.workflow.get_repositories(
                    taskcluster_config.secrets["repositories"],
                    cache_root,
                    default_ssh_key=taskcluster_config.secrets["ssh_key"],
                ),
            )
            self.mercurial.register(self.bus)

            # Setup monitoring for newly created tasks
            self.monitoring = Monitoring(
                taskcluster_config,
                QUEUE_MONITORING,
                taskcluster_config.secrets["admins"],
                MONITORING_PERIOD,
            )
            self.monitoring.register(self.bus)

            # Setup monitoring for newly created community tasks
            if community_config is not None:
                self.community_monitoring = Monitoring(
                    community_taskcluster_config,
                    QUEUE_MONITORING_COMMUNITY,
                    taskcluster_config.secrets["admins"],
                    MONITORING_PERIOD,
                )
                self.community_monitoring.register(self.bus)
github mozilla / code-review / events / code_review_events / workflow.py View on Github external
),
            )
            self.mercurial.register(self.bus)

            # Setup monitoring for newly created tasks
            self.monitoring = Monitoring(
                taskcluster_config,
                QUEUE_MONITORING,
                taskcluster_config.secrets["admins"],
                MONITORING_PERIOD,
            )
            self.monitoring.register(self.bus)

            # Setup monitoring for newly created community tasks
            if community_config is not None:
                self.community_monitoring = Monitoring(
                    community_taskcluster_config,
                    QUEUE_MONITORING_COMMUNITY,
                    taskcluster_config.secrets["admins"],
                    MONITORING_PERIOD,
                )
                self.community_monitoring.register(self.bus)
            else:
                self.community_monitoring = None

            self.bugbug_utils = BugbugUtils(self.workflow.api)
            self.bugbug_utils.register(self.bus)
        else:
            self.workflow = None
            self.mercurial = None
            self.monitoring = None
            self.community_monitoring = None
github mozilla / code-review / events / code_review_events / workflow.py View on Github external
async def process_build(self, build):
        """
        Code review workflow to load all necessary information from Phabricator builds
        received from the webserver
        """
        assert build is not None, "Invalid payload"
        assert isinstance(build, PhabricatorBuild)

        # Update its state
        self.update_state(build)

        if build.state == PhabricatorBuildState.Public:

            # Check if the author is not blacklisted
            if self.is_blacklisted(build.revision):
                return

            # When the build is public, load needed details
            try:
                self.load_patches_stack(build)
                logger.info("Loaded stack of patches", build=str(build))
            except Exception as e:
                logger.warning(
github mozilla / code-review / events / code_review_events / bugbug_utils.py View on Github external
async def process_build(self, build):
        assert build is not None, "Invalid payload"
        assert isinstance(build, PhabricatorBuild)

        # Start risk analysis
        await self.start_risk_analysis(build)
github mozilla / code-review / events / code_review_events / workflow.py View on Github external
)
                        ]
                    },
                    taskcluster_config.secrets["communitytc_pulse_user"],
                    taskcluster_config.secrets["communitytc_pulse_password"],
                    "communitytc",
                )
                # Manually register to set queue as redis
                self.community_pulse.bus = self.bus
                self.bus.add_queue(QUEUE_PULSE_BUGBUG_TEST_SELECT, redis=True)
                self.bus.add_queue(QUEUE_PULSE_TRY_TASK_END, redis=True)
            else:
                self.community_pulse = None

            if exchanges:
                self.pulse = PulseListener(
                    exchanges,
                    taskcluster_config.secrets["pulse_user"],
                    taskcluster_config.secrets["pulse_password"],
                )
                # Manually register to set queue as redis
                self.pulse.bus = self.bus
                self.bus.add_queue(QUEUE_PULSE_AUTOLAND, redis=True)
            else:
                self.pulse = None

        else:
            self.bugbug_utils = None
            self.webserver = None
            self.pulse = None
            self.community_pulse = None
            logger.info("Skipping webserver, bugbug and pulse consumers")
github mozilla / code-review / events / code_review_events / workflow.py View on Github external
(PULSE_TASK_GROUP_RESOLVED, ["#.gecko-level-3.#"])
                ]

            # Create pulse listeners for bugbug test selection task and unit test failures.
            if community_config is not None and test_selection_enabled:
                exchanges[QUEUE_PULSE_TRY_TASK_END] = [
                    (PULSE_TASK_COMPLETED, ["#.gecko-level-1.#"]),
                    (PULSE_TASK_FAILED, ["#.gecko-level-1.#"]),
                    # https://bugzilla.mozilla.org/show_bug.cgi?id=1599863
                    # (
                    #    "exchange/taskcluster-queue/v1/task-exception",
                    #    ["#.gecko-level-1.#"],
                    # ),
                ]

                self.community_pulse = PulseListener(
                    {
                        QUEUE_PULSE_BUGBUG_TEST_SELECT: [
                            (
                                "exchange/taskcluster-queue/v1/task-completed",
                                ["route.project.relman.bugbug.test_select"],
                            )
                        ]
                    },
                    taskcluster_config.secrets["communitytc_pulse_user"],
                    taskcluster_config.secrets["communitytc_pulse_password"],
                    "communitytc",
                )
                # Manually register to set queue as redis
                self.community_pulse.bus = self.bus
                self.bus.add_queue(QUEUE_PULSE_BUGBUG_TEST_SELECT, redis=True)
                self.bus.add_queue(QUEUE_PULSE_TRY_TASK_END, redis=True)