Exemple #1
0
 def test_should_send_on_build_success(self, get_commit):
     get_commit.return_value = "f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"
     with mock.patch(
         "metaci.plan.handlers.trigger_dependent_builds", autospec=True
     ) as handler:
         build_complete.connect(handler, sender="sender")
         build_complete.send(sender="sender", build=self.build, status="success")
         handler.assert_called_once()
Exemple #2
0
def run_build(build_id, lock_id=None):
    reset_database_connection()
    from metaci.build.models import Build

    try:
        build = Build.objects.get(id=build_id)
    except Build.DoesNotExist:
        time.sleep(1)
        build = Build.objects.get(id=build_id)

    try:
        build.run()
        if settings.GITHUB_STATUS_UPDATES_ENABLED:
            res_status = set_github_status.delay(build_id)
            build.task_id_status_end = res_status.id

        build.save()

        build_complete.send(sender=build.__class__,
                            build=build,
                            status=build.get_status())

    except ShutDownImminentException:
        # The Heroku dyno is restarting.
        # Log that, leave the build's status as running,
        # and let the exception fall through to the rq worker to requeue the job.
        build.log += (
            "\nERROR: Build aborted because the Heroku dyno restarted. "
            "MetaCI will try to start a rebuild.")
        build.save()
        raise RequeueJob
    except Exception as e:
        if lock_id:
            cache.delete(lock_id)
        if settings.GITHUB_STATUS_UPDATES_ENABLED:
            res_status = set_github_status.delay(build_id)
            build.task_id_status_end = res_status.id

        build.set_status("error")
        build.log += "\nERROR: The build raised an exception\n"
        build.log += str(e)
        build.save()

        build_complete.send(sender=build.__class__,
                            build=build,
                            status=build.get_status())

    if lock_id:
        cache.delete(lock_id)

    return build.get_status()
Exemple #3
0
def run_build(build_id, lock_id=None):
    reset_database_connection()
    from metaci.build.models import Build
    try:
        build = Build.objects.get(id=build_id)
    except Build.DoesNotExist:
        time.sleep(1)
        build = Build.objects.get(id=build_id)

    try:
        exception = None
        build.run()
        if settings.GITHUB_STATUS_UPDATES_ENABLED:
            res_status = set_github_status.delay(build_id)
            build.task_id_status_end = res_status.id

        build.save()

        build_complete.send(
            sender=build.__class__,
            build=build,
            status=build.get_status(),
        )

    except Exception as e:
        if lock_id:
            cache.delete(lock_id)
        if settings.GITHUB_STATUS_UPDATES_ENABLED:
            res_status = set_github_status.delay(build_id)
            build.task_id_status_end = res_status.id

        build.set_status('error')
        build.log += '\nERROR: The build raised an exception\n'
        build.log += str(e)
        build.save()

        build_complete.send(
            sender=build.__class__,
            build=build,
            status=build.get_status(),
        )

    if lock_id:
        cache.delete(lock_id)

    return build.get_status()