def wrapper(self, *args, **kwargs): key = keyfunc(self, func_attr) value = self._cache.get(key) if value is None: logger.info('cache miss; fetching "%s" and writing to cache', key) # self refers to the instance, which SHOULD have a ._cache attribute value = func(self, *args, **kwargs) value = flatten(value) self._cache.put(key, value) else: logger.info('cache hit; reading "%s" from cache', key) return value
def update(self, props): params = rails_params({'job': props}) logger.debug('Updating Job[%d]: %r', self.id, params) try: res = self._connection.request('/jobs/%s' % self.id, method='PUT', params=params) except CrowdFlowerError, exc: # CrowdFlower sometimes likes to redirect the PUT to a non-API page, # which will raise an error (406 Not Accepted), but we can just # ignore the error since it comes after the update is complete. # This is kind of a hack, since we sometimes want to follow redirects # (e.g., with downloads), but following redirects is more properly # not the default if exc.response.status_code != 406: logger.info('Ignoring 406 "Not Accepted" error: %r', exc); else: raise
def update(self, props): params = rails_params({'job': props}) logger.debug('Updating Job[%d]: %r', self.id, params) try: res = self._connection.request('/jobs/%s' % self.id, method='PUT', params=params) except CrowdFlowerError, exc: # CrowdFlower sometimes likes to redirect the PUT to a non-API page, # which will raise an error (406 Not Accepted), but we can just # ignore the error since it comes after the update is complete. # This is kind of a hack, since we sometimes want to follow redirects # (e.g., with downloads), but following redirects is more properly # not the default if exc.response.status_code != 406: logger.info('Ignoring 406 "Not Accepted" error: %r', exc) else: raise