Skip to content

Instantly share code, notes, and snippets.

@eikeon
Last active December 11, 2015 20:38
Show Gist options
  • Save eikeon/4656148 to your computer and use it in GitHub Desktop.
Save eikeon/4656148 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"runtime"
"time"
"launchpad.net/goamz/aws"
"launchpad.net/~prudhvikrishna/goamz/sqs"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
retryAuth:
auth, err := aws.EnvAuth()
if err != nil {
log.Println("EnvAuth Failed:", err)
time.Sleep(time.Second)
goto retryAuth
}
ssqs := sqs.New(auth, aws.USEast)
queue_name := "twitter-count-q"
timeOutAttribute := sqs.Attribute{"VisibilityTimeout", "3600"}
maxMessageSizeAttribute := sqs.Attribute{"MaximumMessageSize", "65536"}
messageRetentionAttribute := sqs.Attribute{"MessageRetentionPeriod", "345600"}
retryCreate:
q, err := ssqs.CreateQueue(queue_name, []sqs.Attribute{timeOutAttribute, maxMessageSizeAttribute, messageRetentionAttribute})
if err != nil {
log.Println("error creating queue", err)
time.Sleep(time.Second)
goto retryCreate
}
start := time.Date(2006, time.March, 21, 12, 0, 0, 0, time.UTC)
end := time.Date(2011, time.January, 1, 12, 0, 0, 0, time.UTC)
for current := start; current.Before(end); current = current.AddDate(0, 0, 1) {
for h := 0; h < 24; h++ {
hour := current.Format("2006/01/02") + fmt.Sprintf("/%02d/", h)
retrySend:
_, err := q.SendMessage(hour)
if err != nil {
log.Println("error sending message:", err)
time.Sleep(time.Millisecond)
goto retrySend
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment