Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
from johnny.middleware import QueryCacheMiddleware
from johnny.transaction import TransactionManager
from johnny.cache import QueryCacheBackend
from uuid import uuid4
from django.db import connections, DEFAULT_DB_ALIAS, load_backend
# not correctness-critical, after expiry will force complete cache flush
XACT_TIMEOUT = 365 * 86400
@task
def a_celery_task(pxid):
try:
do_something()
except Exception:
two_phase_commit.rollback_prepared(pxid)
else:
two_phase_commit.commit_prepared(pxid)
def defer_something():
@gnosek
gnosek / sortdebversions.pl
Created April 30, 2013 09:10
A simple way to sort Debian package versions
#!/usr/bin/env perl
use strict;
use warnings;
use Dpkg::Version;
use Getopt::Long;
my $head;
my $reverse;
@gnosek
gnosek / environment.yml
Created August 2, 2013 12:12
Cannot return a dict from custom facts
---
- hosts: $host
tasks:
- environment:
- debug: msg="{{ env_HOME }}"
- debug: msg="{{ environment.HOME }}"
- debug: msg="{{ environment }}"
++<=++<=+<=++<=++<=+<=++<=++<=+<=++^^=
++<=++<=+<=++<=++<=+<=++<=++<=+<=++^=
<=++<=++<=++<=++<=++<=++<=++<=++<=++<=++^^
<=++<=++<=++<=++<=++<=++<=++<=++<=++^
++<=++<=+<=++<=++<=+<=++<=++<=+<=++^^=
++<=++<=+<=++<=++<=+<=++<=++<=+<=++^=
<=++<=++<=++<=++<=++<=++<=++<=++<=++<=++^^
<=++<=++<=++<=++<=++<=++<=++<=++<=++^
>>VVVVVVV+^+^+^+^+^+>v+>v+>v+>^+>^+>^+V+V+V+V+V+
<<+<+<+<+^+^+^+>+>+<<^+^+>+>+>+>
<+<+<+<+V+V+V+V+V+>+>+>+>+^+^+<+
<<VV+^+^+^+^+^+
<<+>+>+>+>+<<+V+V+V+V+V+
>>>>><<+<+<+<+^+^+^+>+>+<<^+^+>+>+>+
VVVVV+^+^+^+^+^+<+<+<+V+V+V+V+V+^^^>+>+
<<<<VVV+^+^+^+^+^+>v+>v+>v+>^+>^+>^+V+V+V+V+V+
infinite{.}
@gnosek
gnosek / ansible_test.py
Last active November 6, 2018 03:12
Weird behaviour in ansible
from ansible import playbook, callbacks
def run_playbook(path, extra_vars):
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=1)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=1)
pb = playbook.PlayBook(
playbook=path,
@gnosek
gnosek / assh
Created December 3, 2013 18:12
#!/usr/bin/env python
from ansible.inventory import Inventory
import os
import sys
def get_addr(hostname):
inv = Inventory()
host = inv.get_host(hostname)
if not host:
@gnosek
gnosek / elasticsearch_mapping.py
Last active August 29, 2015 14:01
Dynamic ElasticSearch mappings
MAPPING = {
'_default_': {
'_all': {'enabled': False},
'dynamic_templates': [
{
'analyzed_body': {
'match': 'body',
'match_mapping_type': 'string',
'mapping': {
'type': 'string',
@gnosek
gnosek / run_playbook.py
Last active May 31, 2019 01:15
Run an ansible playbook from python
from ansible import playbook, callbacks
import logging
import pprint
class LoggingCallbacks(callbacks.PlaybookCallbacks):
def log(self, level, msg, *args, **kwargs):
logging.log(level, msg, *args, **kwargs)
def on_task_start(self, name, is_conditional):