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
def upload(self, units): ''' TODO: allow setting Job parameters at the same time ''' headers = {'Content-Type': 'application/json'} # N.b.: CF expects newline-separated JSON, not actual JSON # e.g., this would fail with a status 500: kwargs['data'] = json.dumps(data) data = '\n'.join(json.dumps(unit) for unit in units) job_response = self.request('/jobs/upload', method='POST', headers=headers, data=data) job = Job(job_response['id'], self) job._properties = job_response return job
def upload(self, units): ''' TODO: allow setting Job parameters at the same time ''' headers = {'Content-Type': 'application/json'} # N.b.: CF expects newline-separated JSON, not actual JSON # e.g., this would fail with a status 500: kwargs['data'] = json.dumps(data) data = '\n'.join(json.dumps(unit) for unit in units) job_response = self.request('/jobs/upload', method='POST', headers=headers, data=data) job = Job(job_response['id'], self) job._properties = job_response # bust cache of job_ids self._cache.remove(keyfunc(self, 'job_ids')) return job
def jobs(self): for job_response in self.request('/jobs').json(): job = Job(job_response['id'], self) # populate the Job's properties, since we have all the data anyway job._properties = job_response yield job