示例#1
0
func doRunCommand(c *cli.Context) {
	config := ParseConfigOrDie(c.GlobalString("config"))
	client := github.NewClient(config.GitHubAPIToken)

	// Create and start monitoring queues.
	lock := sync.RWMutex{}
	queues := createQueues(client, config, &lock)
	stopChan := monitorQueues(queues)

	// Graceful stop on SIGTERM and SIGINT.
	s := make(chan os.Signal, 64)
	signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)

	// Compute next tick time for the synchronization event.
	nextTickTime := resetNextTickTime(config.PeriodicSync)
	for {
		select {
		case <-stopChan:
			log.Debug("All queues exited")
			return
		case sig := <-s:
			log.WithField("signal", sig).Debug("received signal")
			for _, q := range queues {
				q.Consumer.Stop()
			}
		case <-time.After(nextTickTime):
			lock.Lock() // Take a write lock, which pauses all queue processing.
			log.Infof("Starting periodic sync")
			runPeriodicSync(client, config)
			nextTickTime = resetNextTickTime(config.PeriodicSync)
			lock.Unlock()
		}
	}
}
示例#2
0
func doLimitsCommand(c *cli.Context) {
	config := ParseConfigOrDie(c.GlobalString("config"))
	client := github.NewClient(config.GitHubAPIToken)

	rl, _, err := client.RateLimits()
	if err != nil {
		log.Fatal(err)
	}

	tmpl, _ := template.New("").Parse(OutputFormat)
	tmpl.Execute(os.Stdout, rl)
}
示例#3
0
// doSyncCommand runs a synchronization job: it fetches all GitHub issues and
// pull requests starting with the From index. It uses the API pagination to
// reduce API calls, and allows a Sleep delay between each page to avoid
// triggering the abuse detection mechanism.
func doSyncCommand(c *cli.Context) {
	config := ParseConfigOrDie(c.GlobalString("config"))
	client := github.NewClient(config.GitHubAPIToken)
	blobStore := storage.NewTransformingBlobStore()

	// Get the list of repositories from command-line (defaults to all).
	repoToSync := c.Args()
	if len(repoToSync) == 0 {
		repoToSync = make([]string, 0, len(config.Repositories))
		for givenName, _ := range config.Repositories {
			repoToSync = append(repoToSync, givenName)
		}
	}

	// Get the repositories instances from their given names.
	repos := make([]*storage.Repository, 0, len(repoToSync))
	for _, givenName := range repoToSync {
		r, ok := config.Repositories[givenName]
		if !ok {
			log.Fatalf("unknown repository %q", givenName)
		}
		repos = append(repos, r)
	}

	// Configure a syncJob taking all issues (opened and closed) and storing
	// in the snapshot store.
	syncOptions := github.DefaultSyncOptions
	syncOptions.From = c.Int("from")
	syncOptions.SleepPerPage = c.Int("sleep")
	syncOptions.State = github.GitHubStateFilterAll
	syncOptions.Storage = storage.StoreSnapshot

	// Create and run the synchronization job.
	log.Warnf("running sync jobs on repositories %s", strings.Join(repoToSync, ", "))
	github.NewSyncCommandWithOptions(client, blobStore, &syncOptions).Run(repos)
}