Skip to content

Instantly share code, notes, and snippets.

@kwas85
Created April 13, 2016 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwas85/8ed689c5da07e7aceda200c7830af6e4 to your computer and use it in GitHub Desktop.
Save kwas85/8ed689c5da07e7aceda200c7830af6e4 to your computer and use it in GitHub Desktop.
A
// Copyright (c) 2016, <your name>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:googleapis_auth/auth_io.dart' as auth;
import 'package:gcloud/db.dart';
import 'package:gcloud/storage.dart';
import 'package:gcloud/pubsub.dart';
import 'package:gcloud/src/datastore_impl.dart' as datastore_impl;
import 'dart:async';
main(List<String> args) async {
// Read the service account credentials from the file.
var jsonCredentials = new File('credentials.json').readAsStringSync();
var credentials = new auth.ServiceAccountCredentials.fromJson(jsonCredentials);
// Get an HTTP authenticated client using the service account credentials.
var scopes = []
..addAll(datastore_impl.DatastoreImpl.SCOPES)
..addAll(Storage.SCOPES)
..addAll(PubSub.SCOPES);
var client = await auth.clientViaServiceAccount(credentials, scopes);
// Instantiate objects to access Cloud Datastore, Cloud Storage
// and Cloud Pub/Sub APIs.
var db = new DatastoreDB(
new datastore_impl.DatastoreImpl(client, 's~project-name'),
defaultPartition: new Partition('test_namespace'));
var storage = new Storage(client, 'project-name');
var pubsub = new PubSub(client, 'project-name');
// !!! No error up to this point. Getting error with status 503 (also without transaction and any other request to datastore)
//DetailedApiRequestError(status: 503, message: Backend Error)
db.withTransaction((t) async{
await db.commit(inserts: [new Test()..test_field = 'Added from dart console']);
});
}
@Kind(idType: IdType.Integer, name: 'Test')
class Test extends Model {
@StringProperty(indexed: true, propertyName: 'test_field')
String test_field;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment