Ejemplo n.º 1
0
func (a *Agent) Bid(ctx context.Context) (price, priority string) {
	p := a.state.Load().(*Pacing)

	atomic.AddInt64(&p.requests, 1)

	if p.sampling < rand.Float64() {
		trace.Count(ctx, "Bidders."+a.Account[0]+".RandomNoBid", 1)
		return
	}

	n := atomic.AddInt64(&p.bids, -1)
	if n < 0 {
		trace.Count(ctx, "Bidders."+a.Account[0]+".NoBid", 1)
		return
	}

	if a.Parameters != nil {
		trace.Count(ctx, "Bidders."+a.Account[0]+".Bid", 1)
		price = a.Parameters.Price
		priority = fmt.Sprintf("%d", a.Parameters.Priority)
	}

	return
}
Ejemplo n.º 2
0
// Process sends a request to query the /check endpoint.
// The response is attached to the request.
func (c *Client) Process(ctx context.Context, r rtb.Request) (err error) {
	ctx = trace.Enter(ctx, "Forensiq")

	// ready?
	if !c.HTTP.Ready() {
		err = ErrUnavailable
		trace.Error(ctx, "Errors.Ready", err)
		return
	}

	var args url.Values

	// fast path in case the request is already prepared
	if p, ok := r.(*request); ok {
		args = p.values
	} else {
		args, err = c.prepare(r)
		if err != nil {
			trace.Error(ctx, "Errors.Prepare", err)
			return
		}
	}

	qs := args.Encode()

	// look into the memory cache or perform the query
	value := c.fromCache(qs)
	if value != nil {
		trace.Count(ctx, "CacheHit", 1)
	} else {
		value, err = c.query(ctx, qs)
		if err != nil {
			trace.Error(ctx, "Errors.Request", err)
			return
		}

		c.intoCache(qs, value)
	}

	// hold the result
	r.Attach(defaults.String(c.Target, "forensiq"), value)

	trace.Leave(ctx, "Check")
	return
}