예제 #1
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
예제 #2
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
예제 #3
0
    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
예제 #4
0
 def jobs(self):
     '''
     This is separated from job_ids to aid in caching. They have no cause
     to be separate except to avoid marshaling issues when encoding/decoding.
     '''
     for job_id in self.job_ids:
         yield Job(job_id, self)
예제 #5
0
    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
예제 #6
0
 def job(self, job_id):
     # doesn't actually call anything
     return Job(job_id, self)
예제 #7
0
 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