Skip to content

Instantly share code, notes, and snippets.

@p-lewis
p-lewis / encode.js
Last active August 4, 2016 05:08
Encode a message in node.js for a Celery worker
var uuid = require("node-uuid");
// Create a message to be consumed by the queuedemo.tasks.add Celery task
// will incorporate arguments x & y as part of `add(x,y)` message
function makeCeleryAddMessage(x, y){
var msgId = uuid.v4();
// This is the outer AMQP envelope
var msgEnvelope = {
@p-lewis
p-lewis / models.py
Created September 2, 2015 17:40
Sample Django model of an expiring message
from datetime import timedelta
from django.conf import settings
from django.db import models
from django.utils import timezone
class ActiveMessagesManager(models.Manager):
use_for_related_fields = True
def get_queryset(self):
@p-lewis
p-lewis / sa_flush_postexec.py
Last active November 9, 2015 19:50
Sample after_flush_postexec session event
from __future__ import print_function
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = sa.create_engine('sqlite:///:memory:', echo=True)
Base = declarative_base()