示例#1
0
 def release_salmon(self):
     """Attempts to unlease the salmon entity.
 """
     salmon = db.get(self.request.params["salmon_key"])
     if salmon and salmon.status == "processing":
         salmon.status = "new"
         salmon.leased_until = None
         salmon.save()
示例#2
0
    def complete_salmon(self):
        """Attempts to mark the salmon entity completed.

    Returns True on success, False otherwise.
    """
        salmon = db.get(self.request.params["salmon_key"])

        if salmon is None:
            raise exc.HTTPExpectationFailed("salmon entity disappeared!")
        elif salmon.status == "complete":
            # let this response return 200 and finish
            logging.warning("salmon stolen and finished. did my lease expire?")
            return
        elif salmon.status == "new":
            raise exc.HTTPExpectationFailed("salmon went backward from processing to new!")

        assert salmon.status == "processing"
        salmon.status = "complete"
        salmon.save()
示例#3
0
    def lease_salmon(self):
        """Attempts to acquire and lease the salmon entity.

    Returns the Salmon on success, otherwise None.

    TODO: unify with complete_salmon
    """
        salmon = db.get(self.request.params["salmon_key"])

        if salmon is None:
            raise exc.HTTPExpectationFailed("no salmon entity!")
        elif salmon.status == "complete":
            # let this response return 200 and finish
            logging.warning("duplicate task already propagated salmon")
        elif salmon.status == "processing" and NOW_FN() < salmon.leased_until:
            # return error code, but don't raise an exception because we don't want
            # the exception handler in post() to catch it and try to release the lease.
            raise exc.HTTPConflict("duplicate task is currently processing!")
        else:
            assert salmon.status in ("new", "processing")
            salmon.status = "processing"
            salmon.leased_until = NOW_FN() + self.LEASE_LENGTH
            salmon.save()
            return salmon