Skip to content

Instantly share code, notes, and snippets.

View mikeengland's full-sized avatar

Mike England mikeengland

  • London, United Kingdom
View GitHub Profile
@mikeengland
mikeengland / django_parallel_tests.py
Last active December 23, 2016 01:15
Overrides the default test database name so that multiple instances of Django parallel tests using the same database instance do not clash e.g. when testing multiple branches at once (like Bamboo's plan branches). Run using: `python manage.py test --testrunner='<path>.<to>.<class>.ParallelTestRunner' --parallel=<num_parallel_processes>`
from datetime import datetime
from django.test.runner import DiscoverRunner
class ParallelTestRunner(DiscoverRunner):
"""
Uses a combination of hours, minutes and microseconds. This should avoid any db name conflicts and when
Django creates the db, the name will abide by the MySQL 16 character limit.
"""
settings.DATABASES[DEFAULT_DB_ALIAS]['NAME'] = datetime.utcnow().strftime('%H%M%f')
@mikeengland
mikeengland / consumer.py
Created July 15, 2018 14:32
Beanstalkd basic consumer/producer example using pystalkd
from pystalkd.Beanstalkd import Connection
conn = Connection(host='127.0.0.1', port=11300)
# watch the queue1 tube
conn.watch('queue1')
# stop watching the default tube
conn.ignore('default')