Esempio n. 1
0
func (a *Account) SendNewAccountEmail(client *gokiq.ClientConfig) error {
	err := client.QueueJob(&NewAccountEmailJob{
		AccountId: a.Id,
	})
	if err != nil {
		return err
	}

	grohl.Log(grohl.Data{
		"queue":   "NewAccountEmailJob",
		"account": a.Id,
	})

	return nil
}
Esempio n. 2
0
func ScheduleCallbacks(client *gokiq.ClientConfig, readerIds []int64, at time.Time, url string) error {
	conn := client.RedisPool.Get()
	defer conn.Close()

	config := gokiq.JobConfig{
		At: at,
	}

	// Don't queue up job within 6 seconds of an existing job
	minScore := at.Add(-3 * time.Second).Unix()
	maxScore := at.Add(3 * time.Second).Unix()

	jobs, err := redis.Strings(conn.Do("ZRANGEBYSCORE", client.RedisNamespace+":schedule", minScore, maxScore))
	userJobs := make(map[int64]int64)
	for _, job := range jobs {
		var entry UserCallbackJobEntry

		if err = json.Unmarshal([]byte(job), &entry); err != nil {
			return err
		}

		userJobs[entry.Args.ReaderId] += 1
	}

	for _, rid := range readerIds {
		if userJobs[rid] > 0 {
			continue
		}

		err = client.QueueJobConfig(&UserCallbackJob{
			Url:      url,
			ReaderId: rid,
		}, config)

		if err != nil {
			return err
		}

		grohl.Log(grohl.Data{
			"schedule_callback": at,
			"url":               url,
			"reader":            rid,
		})
	}

	return nil
}