func (p *Persist) initDB() dynamodb.DynamoDB { db := dynamodb.NewDynamoDB() if db != nil { t, err := db.Register(messageTableName, (*nog.Message)(nil)) if err != nil { panic(err) } pt := dynamodb.ProvisionedThroughput{ReadCapacityUnits: 1, WriteCapacityUnits: 1} if _, err := db.CreateTable(t.TableName, t.AttributeDefinitions, t.KeySchema, pt, nil); err != nil { log.Println("CreateTable:", err) } for { if description, err := db.DescribeTable(messageTableName, nil); err != nil { log.Println("DescribeTable err:", err) } else { log.Println(description.Table.TableStatus) if description.Table.TableStatus == "ACTIVE" { break } } time.Sleep(time.Second) } } return db }
func NewMemoryGinger(dynamo bool) *Ginger { SNS = sns.NewSNS() if dynamo { DB = dynamodb.NewDynamoDB() } else { DB = dynamodb.NewMemoryDB() } fetch, err := DB.Register("fetch", (*Fetch)(nil)) if err != nil { panic(err) } pt := dynamodb.ProvisionedThroughput{ReadCapacityUnits: 8192, WriteCapacityUnits: 8192} if _, err := DB.CreateTable("fetch", fetch.AttributeDefinitions, fetch.KeySchema, pt, nil); err != nil { log.Println(err) } // wait until all tables are active for _, name := range []string{"fetch"} { for { if description, err := DB.DescribeTable(name, nil); err != nil { log.Println("DescribeTable err:", err) } else { log.Println(description.Table.TableStatus) if description.Table.TableStatus == "ACTIVE" { break } } time.Sleep(time.Second) } } return &Ginger{} }