Example #1
0
func (c Creator) creatorWork(body []byte) error {
	apiJob, err := api.Unmarshal(body)
	if err != nil {
		return fmt.Errorf("Umarshalling error with %s: %v", body, err)
	}

	repoInfo := github.RepoInfo{
		ID:           apiJob.RepoInfo.ID,
		Name:         apiJob.RepoInfo.Name,
		Count:        apiJob.RepoInfo.Count,
		CreationDate: apiJob.RepoInfo.CreationDate,
		WorkedOn:     true,
	}

	// Create the repository on the store, claim the work
	key, err := c.db.AddRepo(repoInfo)
	if err != nil {
		return err
	}

	timestamps, err := GetAllTimestamps(c.jobQueue, 100, apiJob.Token, repoInfo)
	if err != nil {
		return fmt.Errorf("Error with %s: %v", body, err)
	}

	lastStar := timestamps[len(timestamps)-1]

	repoInfo.Timestamps = timestamps

	repoInfo.WorkedOn = false
	repoInfo.LastUpdate = time.Now().Format(time.RFC3339)
	repoInfo.LastStarDate = time.Unix(lastStar, 0).Format(time.RFC3339)
	err = c.db.PutRepo(repoInfo, key)
	if err != nil {
		return fmt.Errorf("Put to store error with %s: %v", body, err)
	}

	// TODO: Think if this could be done on the fly first
	// TODO: lib.CanvasJS(timestamps, repoInfo, buffer)
	// Then send the buffer to the database
	// TODO: wrap that into the dbaccess file service.Objects.Insert(*bucketName, object).Media(file).Do()
	// https://cloud.google.com/storage/docs/json_api/v1/json-api-go-samples
	return nil
}