Skip to content

Instantly share code, notes, and snippets.

from django.conf import settings
from django.template import add_to_builtins
import django.template.loader
try:
for lib in settings.TEMPLATE_TAGS:
add_to_builtins(lib)
except AttributeError:
pass
@m0n5t3r
m0n5t3r / gunicorn-upstart.conf.template
Created July 30, 2010 12:27
template for a gunicorn upstart job that can run several instances of a django application
# %(mysite)s - run %(mysite)s instances (default is the main production instance)
#
# This runs gunicorn-django for %(mysite)s; to install:
# * sudo ln -s <this file> /etc/init/%(mysite)s
# * sudo initctl reload-configuration
#
# it expects the following directory layout:
#
# /home/%(mysite)s/public_html
# \-env -> virtualenv
import redis
from django.conf import settings
from django.core.signals import request_finished
try:
from eventlet.corolocal import local
except ImportError:
from threading import local
@suda
suda / gunicorn
Created December 20, 2010 12:38
Gunicorn init.d script (gentoo)
#!/sbin/runscript
# Gunicorn init.d script for gentoo
# Written by Wojtek 'suda' Siudzinski <admin@suda.pl>
# Gist: https://gist.github.com/748335
#
# Sample config (/etc/conf.d/gunicorn):
#
# SERVERS=(
# 'server_name port project_path number_of_workers'
@suda
suda / gunicorn
Created December 20, 2010 14:49
Gunicorn init.d script (debian/ubuntu)
#!/bin/sh
### BEGIN INIT INFO
# Provides: gunicorn
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the gunicorn server
# Description: starts gunicorn using start-stop-daemon
@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
@diox
diox / clear_johnny_cache.py
Created July 5, 2011 16:30
Django management command to clear johnny-cache cache :-)
import sys
import logging
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = ("Invalidates portions of the queryset cache based on the app names"
" or models provided as arguments to the command. If no arguments "
"are provided, nothing is done. To clear the entire queryset "
@phill-tornroth
phill-tornroth / update_large_index.py
Created September 7, 2011 17:21
This is my little batched-strategy for updating really large haystack indexes via a Celery task. It's pretty simple... Each task builds a piece of the index, and then puts a task on the queue for building the next batch. I also use my little @bounce_worke
import logging
from celery.signals import task_postrun
from celery.task import task
from haystack import site
def bounce_worker_after(func):
"""
A decorator which will ensure that the celery worker is shutdown (and subsequently restarted by celery)
after this task is executed.
@chalmerj
chalmerj / gist:1492154
Created December 18, 2011 02:26
Init Script for Graphite/Gunicorn
#! /bin/sh
### BEGIN INIT INFO
# Provides: gunicorn-graphite
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $nginx
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: gunicorn + nginx ubuntu init script
# Description: gunicorn + nginx ubuntu init script
@winhamwr
winhamwr / awesome_task.py
Created May 17, 2012 16:02
Celery base task that adds some niceties for longish-running or singleton jobs.
"""
Celery base task aimed at longish-running jobs that return a result.
``AwesomeResultTask`` adds thundering herd avoidance, result caching, progress
reporting, error fallback and JSON encoding of results.
"""
from __future__ import division
import logging
import simplejson