Exemplo n.º 1
0
    def branch(self, branch):
        """Return a list of builds running on this branch"""
        # TODO: start/enddates

        if branch not in self._branches_cache:
            return self._failed("Branch %s not found" % branch, 404)
        else:
            today = times.now(g.tz).replace(hour=0, minute=0, second=0,
                    microsecond=0)
            date = request.params.get('date')
            if date:
                date = g.tz.localize(datetime.strptime(date, '%Y-%m-%d'))
            else:
                date = today
            c.date = date
            c.today = today
            builds = g.buildapi_cache.get_builds_for_day(date, branch)
            return self._ok(builds)
Exemplo n.º 2
0
    def branch(self, branch):
        """Return a list of builds running on this branch"""
        # TODO: start/enddates

        if branch not in self._branches_cache:
            return self._failed("Branch %s not found" % branch, 404)
        else:
            today = times.now(g.tz).replace(hour=0, minute=0, second=0,
                    microsecond=0)
            date = request.params.get('date')
            if date:
                date = g.tz.localize(datetime.strptime(date, '%Y-%m-%d'))
            else:
                date = today
            c.date = date
            c.today = today
            builds = g.buildapi_cache.get_builds_for_day(date, branch)
            return self._ok(builds)
Exemplo n.º 3
0
    def get_builds_for_day(self, date, branch):
        """
        Returns a list of builds for the given date (a datetime.datetime instance)
        """
        assert date.tzinfo
        key = self.build_key_for_day(date, branch)
        starttime = dt2ts(date)
        endtime = dt2ts(date + oneday)

        if date - now(self.timezone) < 3*oneday:
            # Expire soon
            expire = time.time() + 60
        else:
            # Don't expire
            expire = 0

        return self.cache.get(key, getBuilds, (branch, starttime, endtime),
                expire=expire)
Exemplo n.º 4
0
    def get_builds_for_day(self, date, branch):
        """
        Returns a list of builds for the given date (a datetime.datetime instance)
        """
        assert date.tzinfo
        key = self.build_key_for_day(date, branch)
        starttime = dt2ts(date)
        endtime = dt2ts(date + oneday)

        if date - now(self.timezone) < 3 * oneday:
            # Expire soon
            expire = time.time() + 60
        else:
            # Don't expire
            expire = 0

        return self.cache.get(key,
                              getBuilds, (branch, starttime, endtime),
                              expire=expire)
Exemplo n.º 5
0
    def get_builds_for_date_range(self, starttime, endtime, branch, method=0):
        """
        Returns a list of builds for the given date range. starttime and
        endtime should be datetime.datetime instances.
        """
        assert starttime.tzinfo
        assert endtime.tzinfo

        # Naive version: grab every day individually
        if method == 0:
            retval = []
            d = starttime
            while d < endtime:
                builds = self.get_builds_for_day(d, branch)
                retval.extend(builds)
                d += oneday
            return retval

        # Less naive version? grab the entire date range if anything isn't
        # cached
        if method == 1:
            d = starttime
            need_more = False
            while d < endtime:
                key = self.build_key_for_day(d, branch)
                if not self.cache.has_key(key):
                    need_more = True
                    break
                d += oneday

            if not need_more:
                # Fall back to method 0
                return self.get_builds_for_date_range(starttime,
                                                      endtime,
                                                      branch,
                                                      method=0)

            # Do a big query to get everything
            builds = getBuilds(
                branch,
                dt2ts(starttime),
                dt2ts(endtime),
            )
            retval = builds

            # And then cache the results by date
            days = {}
            for b in builds:
                date = ts2dt(b['starttime'], self.timezone)
                date = date.replace(hour=0, minute=0, second=0, microsecond=0)

                days.setdefault(date, []).append(b)

            for date, builds in days.iteritems():
                if date - now(self.timezone) < 3 * oneday:
                    # Expire soon
                    expire = time.time() + 60
                else:
                    # Expire in half an hour
                    expire = time.time() + 1800
                key = self.build_key_for_day(date, branch)
                self.cache.put(key, builds, expire=expire)

            return retval
Exemplo n.º 6
0
    def get_builds_for_date_range(self, starttime, endtime, branch, method=0):
        """
        Returns a list of builds for the given date range. starttime and
        endtime should be datetime.datetime instances.
        """
        assert starttime.tzinfo
        assert endtime.tzinfo

        # Naive version: grab every day individually
        if method == 0:
            retval = []
            d = starttime
            while d < endtime:
                builds = self.get_builds_for_day(d, branch)
                retval.extend(builds)
                d += oneday
            return retval

        # Less naive version? grab the entire date range if anything isn't
        # cached
        if method == 1:
            d = starttime
            need_more = False
            while d < endtime:
                key = self.build_key_for_day(d, branch)
                if not self.cache.has_key(key):
                    need_more = True
                    break
                d += oneday

            if not need_more:
                # Fall back to method 0
                return self.get_builds_for_date_range(starttime, endtime,
                        branch, method=0)

            # Do a big query to get everything
            builds = getBuilds(branch,
                    dt2ts(starttime),
                    dt2ts(endtime),
                    )
            retval = builds

            # And then cache the results by date
            days = {}
            for b in builds:
                date = ts2dt(b['starttime'], self.timezone)
                date = date.replace(hour=0, minute=0, second=0, microsecond=0)

                days.setdefault(date, []).append(b)

            for date, builds in days.iteritems():
                if date - now(self.timezone) < 3*oneday:
                    # Expire soon
                    expire = time.time() + 60
                else:
                    # Expire in half an hour
                    expire = time.time() + 1800
                key = self.build_key_for_day(date, branch)
                self.cache.put(key, builds, expire=expire)

            return retval