Finding gunicorn worker number inside django app?

2013-11-16 Thread Roy Smith
I'm running django (1.4) with gunicorn (0.17.4) and gevent.  I want to have 
the gunicorn worker number available inside of django, so I can include it 
in log messages and statsd data for tracking purposes.

What I'm doing right now is I put a pre_request hook in my gunicorn config 
file which fakes a HTTP header

def pre_request(worker, req):
   req.headers.append(("X-SONGZA-WORKER", str(worker.age)))

This works, but it seems kind of hacky.  It's also messy because I need to 
process it for every request.  It would be cleaner to do this in 
post_fork(), but I don't see how to communicate any information from the 
worker object available in pre_fork() to something that's visible inside 
django.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fca39909-631e-4558-b835-bcbff0b1b468%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Problem with raw query and using in

2013-11-16 Thread Javier Guerra Giraldez
On Sat, Nov 16, 2013 at 7:40 AM, Thorsten Sanders
 wrote:
> realms=[1]
> data = AuctionData.objects.filter(itemid__exact=itemid,realm__in=realms)
> data2 = AuctionData.objects.raw('SELECT * FROM auctiondata_auctiondata WHERE
> itemid_id=%s AND realm_id in %s ',[itemid,realms])


not sure if it's related. but most SQL adaptors use a tuple for the
IN(...) parameters, not a list.

check http://initd.org/psycopg/docs/usage.html#tuples-adaptation

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFkDaoTSsD%2B8S0rdvOnHVCBxxF6UzRCK9jzscTW4Ff677Yt_dw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Problem with raw query and using in

2013-11-16 Thread Thorsten Sanders

Hello,

wondering if I am doing something wrong or it is a bug, using django 
1.5.5, but also tried with 1.6 resulting in the same problem.


When I do the following:

realms=[1]
data = AuctionData.objects.filter(itemid__exact=itemid,realm__in=realms)
data2 = AuctionData.objects.raw('SELECT * FROM auctiondata_auctiondata 
WHERE itemid_id=%s AND realm_id in %s ',[itemid,realms])


The first query works as expected, but the 2nd one fails, because the 
query ends up as:


SELECT * FROM auctiondata_auctiondata WHERE itemid_id='43552' AND 
realm_id in ('1',)


The last comma shouldnt be there, if I use more than 1 value with the 
realms variable it works and the last comma isn't there.


Greetings,
Thorsten

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/528767D4.8080709%40gmx.net.
For more options, visit https://groups.google.com/groups/opt_out.