Skip to content

Instantly share code, notes, and snippets.

View HackerWilson's full-sized avatar

Wilson HackerWilson

View GitHub Profile
@HackerWilson
HackerWilson / models.py
Last active June 29, 2016 20:10
Django create mptt groups in two ways.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
方法二:mptt自有的方法见http://django-mptt.github.io/django-mptt/models.html#registration-of-existing-models
'''
import mptt
from django.contrib.auth.models import Group
// kills long running ops in MongoDB (taking seconds as an arg to define "long")
// attempts to be a bit safer than killing all by excluding replication related operations
// and only targeting queries as opposed to commands etc.
killLongRunningOps = function(maxSecsRunning) {
currOp = db.currentOp();
for (oper in currOp.inprog) {
op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
print("Killing opId: " + op.opid