Created
April 16, 2015 21:28
-
-
Save kevin-cantwell/8eb209911160af83042f to your computer and use it in GitHub Desktop.
Drain Sampler. Prints out dynamo keys for items currently in the drain.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "time" | |
| "github.com/timehop/jimmy/redis" | |
| ) | |
| func main() { | |
| r := redis.NewPool("redis://<redacted>:6379", redis.DefaultConfig) | |
| for { | |
| members, err := r.SRandMember("import:drain.backlog", 10) | |
| if err != nil { | |
| panic(err) | |
| } | |
| for _, member := range members { | |
| var c Content | |
| if err := json.Unmarshal([]byte(member), &c); err != nil { | |
| panic(err) | |
| } | |
| // Print out the dynamo user_key and date_key | |
| userID := int(c.UserID) | |
| date := time.Unix(int64(c.At), 0).UTC() | |
| userKey := fmt.Sprintf("%s:%d", date.Format("02012006"), userID) | |
| dateKey := fmt.Sprintf("%10d:%s:%s", int64(c.At), c.ContentType, c.ContentID) | |
| // Print in two columns | |
| fmt.Printf("%-5s \t%v\n", userKey, dateKey) | |
| // Uncomment the below to print out the data field | |
| // if c.ContentType == "facebook_feed" { | |
| // fmt.Printf("%s", c.Data) | |
| // } | |
| } | |
| } | |
| } | |
| type Content struct { | |
| AccountID float64 `json:"account_id"` | |
| At float64 `json:"at"` | |
| ClientID string `json:"client_id"` | |
| ContentID string `json:"content_id"` | |
| ContentType string `json:"content_type"` | |
| Data string `json:"data"` | |
| Platform bool `json:"platform"` | |
| Uid string `json:"uid"` | |
| UserID float64 `json:"user_id"` | |
| UserPartnerID float64 `json:"user_partner_id"` | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment