def _create_examples(self): examples = [] for i, name in enumerate(self.NAMES.split(' ')): examples.append({'id': uniqid(), 'name': name, 'value': i}) with self.interface.get_engine().begin() as connection: connection.execute(Example.__table__.insert(), *examples)
def initiate(self, session, data): Request = self.docket_entity.bind('docket.entity/1.0/flux/1.0/request') id = uniqid() attrs = data['input'] try: attrs = self.operation['schema'].unserialize(attrs) except ValidationError: log('exception', 'initiation of create-request operation failed') return self.invalidation(error='invalid-input') wait_for_completion = attrs.pop('wait_for_completion', True) if wait_for_completion: SubscribedTask.queue_http_task('complete-request-operation', self.flux.prepare('flux/1.0/request', 'task', None, {'task': 'complete-request-operation', 'request_id': id, 'process_id': data['id']}), topic='request:completed', aspects={'id': id}, timeout=259200) attrs['id'] = id try: request = Request.create(**attrs) except Exception: log('exception', 'initiation of create-request operation failed') return self.invalidation(error='failed') if wait_for_completion: return self.executing() else: outcome = ('created' if request.status in ('pending', 'prepared') else 'failed') return self.outcome(outcome, { 'request': surrogate.construct('flux.surrogates.request', request),})
def _create_examples(self): examples = [] for name, value in self.EXAMPLES: examples.append({'id': uniqid(), 'name': name, 'value': value}) with self.interface.get_engine().begin() as connection: connection.execute(Example.__table__.insert(), *examples)
def create(cls, session, **attrs): subject = cls(**attrs) if not subject.id: subject.id = uniqid() if subject.created: subject.modified = subject.created else: subject.created = subject.modified = current_timestamp() cls._check_duplicate_name(session, subject) session.add(subject) return subject
def _dispatch_request(self, request, response): directory = self.configuration['upload_directory'] if request.method == 'GET': return elif request.method != 'POST': raise MethodNotAllowed() mapping = {} for name, uploaded_file in request.files.iteritems(): filename = mapping[name] = '%s_%s' % ( uniqid(), secure_filename(uploaded_file.filename)) uploaded_file.save(os.path.join(directory, filename)) response.mimetype = 'text/html' response.data = Json.serialize(mapping)
def initiate(self, session, data): Request = self.docket_entity.bind('docket.entity/1.0/flux/1.0/request') id = uniqid() attrs = data['input'] try: attrs = self.operation['schema'].unserialize(attrs) except ValidationError: log('exception', 'initiation of create-request operation failed') return self.invalidation(error='invalid-input') wait_for_completion = attrs.pop('wait_for_completion', True) if wait_for_completion: SubscribedTask.queue_http_task( 'complete-request-operation', self.flux.prepare( 'flux/1.0/request', 'task', None, { 'task': 'complete-request-operation', 'request_id': id, 'process_id': data['id'] }), topic='request:completed', aspects={'id': id}, timeout=259200) attrs['id'] = id try: request = Request.create(**attrs) except Exception: log('exception', 'initiation of create-request operation failed') return self.invalidation(error='failed') if wait_for_completion: return self.executing() else: outcome = ('created' if request.status in ('pending', 'prepared') else 'failed') return self.outcome( outcome, { 'request': surrogate.construct('flux.surrogates.request', request), })