Skip to content

Commit 771b89a

Browse files
committed
Clean up logger errors - Molnix
1 parent cbd1e07 commit 771b89a

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

api/management/commands/sync_molnix.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def get_datetime(datetime_string):
107107
return None
108108
return date_parser.parse(datetime_string)
109109

110+
110111
def get_status_message(positions_messages, deployments_messages, positions_warnings, deployments_warnings):
111112
msg = ''
112113
msg += 'Summary of Open Positions Import:\n\n'
@@ -125,26 +126,21 @@ def get_status_message(positions_messages, deployments_messages, positions_warni
125126
msg += '\n\n'
126127
return msg
127128

128-
def add_tags_to_obj(obj, tags):
129-
# We clear all tags first, and then re-add them
130-
tag_molnix_ids = [t['id'] for t in tags]
131-
obj.molnix_tags.clear()
132-
for molnix_id in tag_molnix_ids:
133-
try:
134-
t = MolnixTag.objects.get(molnix_id=molnix_id)
135-
except:
136-
logger.error('ERROR - tag not found: %d' % molnix_id)
137-
continue
138-
obj.molnix_tags.add(t)
139-
obj.save()
140129

130+
def add_tags_to_obj(obj, tags):
131+
_ids = [int(t['id']) for t in tags]
132+
tags = list( # Fetch all at once
133+
MolnixTag.objects.filter(molnix_id__in=_ids)
134+
)
135+
if len(tags) != len(_ids): # Show warning if all tags are not available
136+
missing_tag_ids = list(set(_ids) - set([tag.id for tag in tags]))
137+
logger.warning(f'Missing _ids: {missing_tag_ids}')
138+
# or ^^^^^^^ logger.error if we need to add molnix tags manually.
139+
obj.molnix_tags.set(tags) # Add new ones, remove old ones
141140

142141

143142
def sync_deployments(molnix_deployments, molnix_api, countries):
144-
#import json
145-
#print(json.dumps(molnix_deployments, indent=2))
146143
molnix_ids = [d['id'] for d in molnix_deployments]
147-
148144
warnings = []
149145
messages = []
150146
successful_creates = 0

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ x-server: &base_server_setup
2727
# Appeal API
2828
APPEALS_USER: ${APPEALS_USER}
2929
APPEALS_PASS: ${APPEALS_PASS}
30+
# Sentry
31+
SENTRY_DSN: ${SENTRY_DSN}
32+
SENTRY_SAMPLE_RATE: ${SENTRY_SAMPLE_RATE:-0.2}
33+
3034
env_file:
3135
- .env
3236
volumes:

0 commit comments

Comments
 (0)