Exemplo n.º 1
0
    def txn_async():
        build, should_update = yield get_build_async(False)
        if not should_update:  # pragma: no cover
            raise ndb.Return(build, False)
        now = utils.utcnow()
        build.proto.status = common_pb2.CANCELED
        build.status_changed_time = now
        build.result_details = result_details
        build.proto.summary_markdown = summary_markdown
        build.proto.canceled_by = identity_str
        build.proto.end_time.FromDatetime(now)
        build.clear_lease()
        futs = [
            build.put_async(),
            events.on_build_completing_async(build),
            _put_output_properties_async(build.key, result_details),
            model.BuildSteps.cancel_incomplete_steps_async(
                build.key.id(), build.proto.end_time)
        ]

        sw = build.parse_infra().swarming
        # TODO(nodir): remove, in favor of swarming.TaskSyncBuild.
        if sw.hostname and sw.task_id:  # pragma: no branch
            futs.append(
                swarming.cancel_task_transactionally_async(
                    sw.hostname, sw.task_id))
        yield futs
        raise ndb.Return(build, True)
Exemplo n.º 2
0
    def txn():
        build = _get_leasable_build(build_id)

        if build.is_ended:
            if (build.proto.status == status
                    and build.result_details == result_details
                    and build.url == url):
                return False, build
            raise errors.BuildIsCompletedError(
                'Build %s has already completed' % build_id)
        _check_lease(build, lease_key)

        now = utils.utcnow()
        build.proto.status = status
        build.status_changed_time = now
        build.proto.end_time.FromDatetime(now)
        if url is not None:  # pragma: no branch
            build.url = url
        build.result_details = result_details
        if new_tags:
            build.tags.extend(new_tags)
            build.tags = sorted(set(build.tags))
        build.clear_lease()

        _fut_results(
            build.put_async(),
            events.on_build_completing_async(build),
            _put_output_properties_async(build.key, result_details),
        )
        return True, build
Exemplo n.º 3
0
    def txn():
        build = model.Build.get_by_id(build_id)
        if not build:  # pragma: no cover
            return None

        build.proto.status = status
        build.proto.summary_markdown = summary_markdown
        build.proto.end_time.FromDatetime(end_time)
        ndb.Future.wait_all(
            [build.put_async(),
             events.on_build_completing_async(build)])
        return build
Exemplo n.º 4
0
  def txn_async(build_key):
    now = utils.utcnow()
    build = yield build_key.get_async()
    if not build or build.status not in expected_statuses:
      raise ndb.Return(False, build)  # pragma: no cover

    build.clear_lease()
    build.proto.status = common_pb2.INFRA_FAILURE
    build.proto.status_details.timeout.SetInParent()
    build.proto.end_time.FromDatetime(now)
    build.status_changed_time = now
    yield build.put_async(), events.on_build_completing_async(build)
    raise ndb.Return(True, build)
Exemplo n.º 5
0
    def txn_async():
        build = yield model.Build.get_by_id_async(build_id)
        if build is None or not _sync_build_in_memory(build, result):
            raise ndb.Return(None)

        futures = [build.put_async()]

        if build.status == model.BuildStatus.STARTED:
            futures.append(events.on_build_starting_async(build))
        elif build.status == model.BuildStatus.COMPLETED:  # pragma: no branch
            futures.append(events.on_build_completing_async(build))

        yield futures
        raise ndb.Return(build)
Exemplo n.º 6
0
    def txn_async():
        build = yield get_async()

        orig_status = build.status

        futures = []

        if 'build.output.properties' in update_paths:
            futures.append(
                model.BuildOutputProperties(
                    key=model.BuildOutputProperties.key_for(build.key),
                    properties=out_prop_bytes,
                ).put_async())

        if model_build_proto_mask:  # pragma: no branch
            # Merge the rest into build.proto using model_build_proto_mask.
            model_build_proto_mask.merge(req.build, build.proto)

        # If we are updating build status, update some other dependent fields
        # and schedule notifications.
        status_changed = orig_status != build.proto.status
        if status_changed:
            if build.proto.status == common_pb2.STARTED:
                if not build.proto.HasField('start_time'):  # pragma: no branch
                    build.proto.start_time.FromDatetime(now)
                futures.append(events.on_build_starting_async(build))
            else:
                assert model.is_terminal_status(
                    build.proto.status), build.proto.status
                build.clear_lease()
                if not build.proto.HasField('end_time'):  # pragma: no branch
                    build.proto.end_time.FromDatetime(now)
                futures.append(events.on_build_completing_async(build))

        if 'build.steps' in update_paths:
            # TODO(crbug.com/936892): reject requests with a terminal build status
            # and incomplete steps, when
            # https://chromium-review.googlesource.com/c/infra/infra/+/1553291
            # is deployed.
            futures.append(build_steps.put_async())
        elif build.is_ended:
            futures.append(
                model.BuildSteps.cancel_incomplete_steps_async(
                    req.build.id, build.proto.end_time))

        futures.append(build.put_async())
        yield futures
        raise ndb.Return(build, status_changed)
Exemplo n.º 7
0
    def txn_async():
        build = yield model.Build.get_by_id_async(build_id)
        if not build:  # pragma: no cover
            raise ndb.Return(None)
        made_change = _sync_build_in_memory(build, task_result)
        if not made_change:
            raise ndb.Return(None)

        futures = [build.put_async()]

        if build.proto.status == common_pb2.STARTED:
            futures.append(events.on_build_starting_async(build))
        elif build.is_ended:  # pragma: no branch
            futures.append(
                model.BuildSteps.cancel_incomplete_steps_async(
                    build_id, build.proto.end_time))
            futures.append(events.on_build_completing_async(build))

        yield futures
        raise ndb.Return(build)
Exemplo n.º 8
0
    def txn():
        bundle = model.BuildBundle.get(build_id, infra=True)
        if not bundle:  # pragma: no cover
            return None
        build = bundle.build
        status_changed = _sync_build_with_task_result_in_memory(
            build, bundle.infra, task_result)
        if not status_changed:
            return None

        futures = [bundle.put_async()]

        if build.proto.status == common_pb2.STARTED:
            futures.append(events.on_build_starting_async(build))
        elif build.is_ended:  # pragma: no branch
            futures.append(
                model.BuildSteps.cancel_incomplete_steps_async(
                    build_id, build.proto.end_time))
            futures.append(events.on_build_completing_async(build))

        for f in futures:
            f.check_success()
        return build
Exemplo n.º 9
0
 def txn():
   build.put()
   events.on_build_completing_async(build).get_result()