Beispiel #1
0
    def update(self, props):
        params = rails_params({'job': props})
        logger.debug('Updating Job[%d]: %r', self.id, params)
        res = self._connection.request('/jobs/%s' % self.id, method='PUT', params=params)

        # reset cached properties
        self._cache.remove(keyfunc(self, 'properties'))

        return res
Beispiel #2
0
 def launch(self, units_count, channels=('on_demand',)):
     '''
     `units_count` is the number of units to order
     `channels` should be some non-empty combination of 'cf_internal'
         (sandbox mode) and / or 'on_demand' (normal)
     '''
     channels = list(channels)
     data = rails_params(dict(channels=channels, debit=dict(units_count=units_count)))
     res = self._connection.request('/jobs/%s/orders' % self.id, method='POST', params=data)
     self._cache_flush('properties')
     return res
Beispiel #3
0
 def create_job(self, props):
     '''
     Creates an empty job with given `props` attributes.
     '''
     params = rails_params({'job': props})
     job_response = self.request('/jobs', method='POST', params=params)
     job = Job(job_response['id'], self)
     job._properties = job_response
     # bust cache of job_ids
     self._cache.remove(keyfunc(self, 'job_ids'))
     return job
Beispiel #4
0
 def create_job(self, props):
     '''
     Creates an empty job with given `props` attributes.
     '''
     params = rails_params({'job': props})
     job_response = self.request('/jobs', method='POST', params=params)
     job = Job(job_response['id'], self)
     job._properties = job_response
     # bust cache of job_ids
     self._cache.remove(keyfunc(self, 'job_ids'))
     return job
Beispiel #5
0
 def launch(self, units_count, channels=('on_demand', )):
     '''
     `units_count` is the number of units to order
     `channels` should be some non-empty combination of 'cf_internal'
         (sandbox mode) and / or 'on_demand' (normal)
     '''
     channels = list(channels)
     data = rails_params(
         dict(channels=channels, debit=dict(units_count=units_count)))
     res = self._connection.request('/jobs/%s/orders' % self.id,
                                    method='POST',
                                    params=data)
     self._cache_flush('properties')
     return res
Beispiel #6
0
    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
Beispiel #7
0
    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
Beispiel #8
0
 def set_tags(self, tags):
     params = rails_params({'tags': tags})
     self._connection.request('/jobs/%s/tags' % self.id,
                              method='PUT',
                              params=params)
     self._cache_flush('tags')
Beispiel #9
0
 def add_tags(self, tags):
     params = rails_params({'tags': tags})
     self._connection.request('/jobs/%s/tags' % self.id, method='POST', params=params)
     self._cache_flush('tags')
Beispiel #10
0
 def add_tags(self, tags):
     params = rails_params({'tags': tags})
     self._connection.request('/jobs/%s/tags' % self.id, method='POST', params=params)
     self._cache.remove(keyfunc(self, 'tags'))