Skip to content

Commit

Permalink
Merge pull request #780 from security-force-monitor/hcg/correct-signals
Browse files Browse the repository at this point in the history
Properly manage Haystack signals during import
  • Loading branch information
hancush authored Sep 27, 2021
2 parents 071617d + 4cb5b14 commit 185be98
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 8 deletions.
Binary file modified configs/settings_local_numbersix.py.gpg
Binary file not shown.
Binary file modified configs/settings_local_production.py.gpg
Binary file not shown.
Binary file modified configs/settings_local_sahel.py.gpg
Binary file not shown.
Binary file modified configs/settings_local_staging.py.gpg
Binary file not shown.
7 changes: 3 additions & 4 deletions sfm_pc/management/commands/import_google_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from tqdm import tqdm

from django.apps import apps
from django.core.cache import cache
from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand
Expand Down Expand Up @@ -111,24 +112,22 @@ def get_credentials(self, *, scopes, credentials_file='credentials.json'):
return credentials

def disconnectSignals(self):
from django.db.models.signals import post_save
from complex_fields.base_models import object_ref_saved
from sfm_pc.signals import update_membership_index, update_composition_index

object_ref_saved.disconnect(receiver=update_membership_index, sender=MembershipPerson)
object_ref_saved.disconnect(receiver=update_composition_index, sender=Composition)

settings.HAYSTACK_SIGNAL_PROCESSOR = None
apps.get_app_config('haystack').signal_processor.teardown()

def connectSignals(self):
from django.db.models.signals import post_save
from complex_fields.base_models import object_ref_saved
from sfm_pc.signals import update_membership_index, update_composition_index

object_ref_saved.connect(receiver=update_membership_index, sender=MembershipPerson)
object_ref_saved.connect(receiver=update_composition_index, sender=Composition)

settings.HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
apps.get_app_config('haystack').signal_processor.setup()

def handle(self, *args, **options):

Expand Down
7 changes: 6 additions & 1 deletion sfm_pc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from .settings_local import DATABASE_URL, GOOGLE_MAPS_KEY, \
SECRET_KEY, DEBUG, ALLOWED_HOSTS, IMPORTER_USER, SOLR_URL, \
CACHES, OSM_API_KEY, HAYSTACK_CONNECTIONS, \
HAYSTACK_DOCUMENT_FIELD, HAYSTACK_SIGNAL_PROCESSOR
HAYSTACK_DOCUMENT_FIELD

# Application definition

Expand Down Expand Up @@ -362,3 +362,8 @@

# Format this string with the user's language code
RESEARCH_HANDBOOK_URL = "https://help.securityforcemonitor.org"

HAYSTACK_SIGNAL_PROCESSOR = os.getenv(
'DJANGO_HAYSTACK_SIGNAL_PROCESSOR',
'haystack.signals.RealtimeSignalProcessor'
)
3 changes: 0 additions & 3 deletions sfm_pc/settings_local.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,3 @@
}

HAYSTACK_DOCUMENT_FIELD = 'content'

# Update index on model change
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

0 comments on commit 185be98

Please sign in to comment.