コード例 #1
0
ファイル: slack.go プロジェクト: joelhawksley/helios
func connectSlackRTM(h *helios.Engine, s *SlackService) {
	err := backoff.Retry(func() error {
		h.Debug("Connecting to slack rtm")
		err := runSlackRTM(h, s)
		if err != nil {
			h.Warn("Failed to start slack rtm. Retrying.", "error", err.Error())
		}
		return err
	}, backoff.NewExponentialBackOff())
	if err != nil {
		s.Messages <- helios.NewError("Slack service error: %v", err)
	}
}
コード例 #2
0
ファイル: fetch.go プロジェクト: joelhawksley/helios
func userRoutine(u User, g *GithubService) error {

	ts := tokenSource{
		&oauth2.Token{
			AccessToken: u.AccessToken,
		},
	}

	tc := oauth2.NewClient(oauth2.NoContext, ts)

	client := github.NewClient(tc)

	//List Options Page, PerPage
	opts := github.ListOptions{1, 1}

	for {
		events, resp, err := client.Activity.ListEventsPerformedByUser(u.Username, false, &opts)
		if err != nil {
			g.EventChan <- helios.NewError("Problem retrieving events for user: %s. Error: %v", u.Username, err)
		}

		newEventTime := g.LastEvent.EventTime

		if len(events) > 0 {
			newEventTime = *events[0].CreatedAt
		}

		// read in last event and compare to new event time
		g.LastEvent.Lock()
		dur := g.LastEvent.EventTime.Sub(newEventTime)
		if dur.Seconds() > 0.0 {
			g.LastEvent.EventTime = newEventTime
			g.EventChan <- helios.NewMessage(events[0])
		}
		g.LastEvent.Unlock()

		// Wait as long as the X-Poll-Interval header says to
		interval, err := strconv.ParseInt(resp.Header["X-Poll-Interval"][0], 10, 8)
		if err != nil {
			// if strconv failed for whatever reason, use the default X-Poll-Interval value of 60
			time.Sleep(60 * time.Second)
		} else {
			time.Sleep(time.Duration(interval) * time.Second)
		}
	}

	panic("Shouldn't be here")
}