from couchdbkit.exceptions import ResourceNotFound from gevent import monkey; monkey.patch_all() import sys import gevent from restkit.session import set_session set_session("gevent") from gevent.pool import Pool from django.core.management.base import BaseCommand from django.conf import settings setattr(settings, 'COUCHDB_TIMEOUT', 999999) from couchdbkit.ext.django.loading import get_db DESIGN_DOC_VIEW = '_all_docs' DESIGN_SK = "_design" DESIGN_EK = "_design0" POOL_SIZE=12 REPEAT_INTERVAL = getattr(settings,'PRIME_VIEWS_INTERVAL', 3600) #apps_with_dbs = [ # 'couchforms', #commcarehq for everything # 'auditcare', # 'couchlog', # ] def get_unique_dbs(): """ In order to not break abstraction barrier, we walk through all the COUCH_DATABASES and assemble the unique set of databases (based upon the URL) to prime the views and all the design docs in it. """
from gevent import monkey; monkey.patch_all() from gevent.pool import Pool from restkit.session import set_session; set_session("gevent") class PillowtopConfigurationException(Exception): pass def import_pillows(): try: from django.conf import settings except Exception, ex: #if we are not in a django context, then import local pillowsettings print "django import" print ex import pillowsettings as settings pillowtops = [] if hasattr(settings, 'PILLOWTOPS'): for full_str in settings.PILLOWTOPS: comps = full_str.split('.') pillowtop_class_str = comps[-1] mod_str = '.'.join(comps[0:-1]) mod = __import__(mod_str, {},{},[pillowtop_class_str]) if hasattr(mod, pillowtop_class_str): pillowtop_class = getattr(mod, pillowtop_class_str) pillowtops.append(pillowtop_class()) else: raise PillowtopConfigurationException("Error, the pillow class %s could not be imported" % full_str) return pillowtops
from gevent import monkey monkey.patch_all() from itertools import islice from casexml.apps.case.models import CommCareCase import time from corehq.apps.hqcase.dbaccessors import get_number_of_cases_in_domain, \ get_case_ids_in_domain import sys from restkit.session import set_session set_session("gevent") from gevent.pool import Pool from couchdbkit.exceptions import ResourceNotFound from django.core.management.base import LabelCommand from corehq.apps.indicators.models import CaseIndicatorDefinition, \ FormIndicatorDefinition, DocumentMismatchError, DocumentNotInDomainError, \ FormLabelIndicatorDefinition from couchforms.models import XFormInstance from dimagi.utils.couch.database import iter_docs from mvp.models import MVP POOL_SIZE = 10 class Command(LabelCommand): help = "Update MVP indicators in existing cases and forms." args = "<domain> <case or form> <case or form label> <start at record #>" label = "" start_at_record = 0 domains = None
""" filedir = os.path.dirname(__file__) submodules_list = os.listdir(os.path.join(filedir, source_root_parent)) for d in submodules_list: if d == "__init__.py" or d == '.' or d == '..': continue sys.path.insert(1, os.path.join(filedir, source_root_parent, d)) sys.path.append(os.path.join(filedir, source_root_parent)) def _set_source_root(source_root): filedir = os.path.dirname(__file__) sys.path.insert(1, os.path.join(filedir, source_root)) if __name__ == "__main__": _set_source_root_parent('submodules') _set_source_root(os.path.join('corehq', 'ex-submodules')) _set_source_root(os.path.join('custom', '_legacy')) # proxy for whether we're running gunicorn with -k gevent if "gevent" in sys.argv: from restkit.session import set_session; set_session("gevent") from gevent.monkey import patch_all; patch_all() os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
# gevent-patching subprocess) GEVENT_COMMANDS = ( GeventCommand('mvp_force_update', None), GeventCommand('run_gunicorn', None), GeventCommand('preindex_everything', None), GeventCommand('migrate_multi', None), GeventCommand('prime_views', None), GeventCommand('ptop_preindex', None), GeventCommand('sync_prepare_couchdb_multi', None), GeventCommand('sync_couch_views', None), GeventCommand('celery', '-P gevent'), GeventCommand('populate_form_date_modified', None), GeventCommand('migrate_domain_from_couch_to_sql', None), GeventCommand('migrate_multiple_domains_from_couch_to_sql', None), ) if len(sys.argv) > 1 and _should_patch_gevent(sys.argv, GEVENT_COMMANDS): from restkit.session import set_session set_session(b"gevent") from gevent.monkey import patch_all patch_all(subprocess=True) from psycogreen.gevent import patch_psycopg patch_psycopg() # workaround for https://github.com/smore-inc/tinys3/issues/33 mimetypes.init() patch_jsonfield() set_default_settings_path(sys.argv) from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)