Skip to content

Commit 6664459

Browse files
committed
Merge remote-tracking branch 'origin/master' into 510-sf-updated
2 parents 5ddfbd4 + 730eb43 commit 6664459

File tree

8 files changed

+49
-20
lines changed

8 files changed

+49
-20
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ start_env.sh
2323
*secrets*
2424
*kustomization*
2525
src/.venv/
26+
src/server/secrets_dict.py
27+

src/server/api/.optic/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/server/api/API_ingest/ingest_sources_from_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def start():
1010
logger.debug(" Finished fetching Salesforce contacts")
1111

1212
logger.debug(" Fetching Shelterluv people")
13-
shelterluv_people.store_shelterluv_people_all()
14-
logger.debug(" Finished fetching Shelterluv people")
13+
slp_count = shelterluv_people.store_shelterluv_people_all()
14+
logger.debug(" Finished fetching Shelterluv people - %d records" , slp_count)
1515

1616
logger.debug(" Fetching Shelterluv events")
1717
sle_count = sl_animal_events.store_all_animals_and_events()
Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import os
22

3-
from sqlalchemy.orm import sessionmaker
3+
import structlog
44
from simple_salesforce import Salesforce
5+
from sqlalchemy.orm import sessionmaker
6+
57
from config import engine
68
from models import SalesForceContacts
79

8-
import structlog
910
logger = structlog.get_logger()
1011

12+
TEST_MODE = os.getenv("TEST_MODE") # if not present, has value None
13+
1114
def store_contacts_all():
1215
Session = sessionmaker(engine)
1316
with Session() as session:
@@ -16,10 +19,27 @@ def store_contacts_all():
1619
session.execute("TRUNCATE TABLE salesforcecontacts")
1720

1821
logger.debug("retrieving the latest salesforce contacts data")
19-
sf = Salesforce(domain=os.getenv('SALESFORCE_DOMAIN'), password=os.getenv('SALESFORCE_PW'), username=os.getenv('SALESFORCE_USERNAME'), security_token=os.getenv('SALESFORCE_SECURITY_TOKEN'))
22+
23+
if os.path.exists('server/bin/connected-app-secrets.pem'):
24+
pem_file = 'server/bin/connected-app-secrets.pem'
25+
elif os.path.exists('bin/connected-app-secrets.pem'):
26+
pem_file = 'bin/connected-app-secrets.pem'
27+
else:
28+
logger.error("Missing salesforce jwt private key pem file, skipping data pull")
29+
return
30+
31+
sf = Salesforce(username=os.getenv('SALESFORCE_USERNAME'), consumer_key=os.getenv('SALESFORCE_CONSUMER_KEY'),
32+
privatekey_file=pem_file)
2033
results = sf.query("SELECT Contact_ID_18__c, FirstName, LastName, Contact.Account.Name, MailingCountry, MailingStreet, MailingCity, MailingState, MailingPostalCode, Phone, MobilePhone, Email FROM Contact")
34+
logger.debug("%d total Salesforce contact records", results['totalSize'])
35+
if TEST_MODE:
36+
logger.debug("running in test mode so only downloading first page of Salesforce contacts")
37+
38+
total_records = 0
2139
done = False
2240
while not done:
41+
total_records += len(results['records'])
42+
logger.debug("Query returned %d Salesforce contact records, total %d", len(results['records']), total_records)
2343
for row in results['records']:
2444
account_name = row['Account']['Name'] if row['Account'] is not None else None
2545
contact = SalesForceContacts(contact_id=row['Contact_ID_18__c'],
@@ -33,10 +53,12 @@ def store_contacts_all():
3353
mailing_zip_postal_code=row['MailingPostalCode'],
3454
phone=row['Phone'],
3555
mobile=row['MobilePhone'],
36-
email=['Email'])
56+
email=row['Email'])
3757
session.add(contact)
38-
done = results['done']
39-
if not done:
40-
results = sf.query_more(results['nextRecordsUrl'])
58+
# if in test mode only return first page of results
59+
done = results['done'] if not TEST_MODE else True
60+
if not done:
61+
results = sf.query_more(results['nextRecordsUrl'], True)
62+
logger.debug("Committing downloaded contact records")
4163
session.commit()
42-
logger.debug("finished downloading latest salesforce contacts data")
64+
logger.debug("finished downloading latest salesforce contacts data")

src/server/api/API_ingest/shelterluv_people.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ def store_shelterluv_people_all():
7070
animal_ids=person["Animal_ids"]))
7171
offset += LIMIT
7272
has_more = response["has_more"] if not TEST_MODE else response["has_more"] and offset < 1000
73+
if offset % 1000 == 0:
74+
logger.debug("Reading offset %s", str(offset))
7375
session.commit()
7476

75-
logger.debug("Finish getting shelterluv contacts from people table")
77+
logger.debug("Finished getting shelterluv contacts from people table")
78+
return offset
7679

src/server/api/admin_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ def start_job():
224224

225225
if running_job :
226226
# There was a running job already
227-
logger.warn("Request to start job, but job_id " + str(running_job) + " already executing")
227+
logger.warn("Request to start job, but job_id %s already executing", str(running_job))
228228
return None
229229
else:
230-
logger.info("Assigned job_id %s" + str(job_id ) )
230+
logger.info("Assigned job_id %s" , str(job_id ) )
231231
return job_id
232232

233233

src/server/pipeline/flow_script.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,26 @@ def start_flow():
6767
# 6. Update each row in pdp_contacts to give it a match id
6868
# corresponding to its connected componenet.
6969

70-
logger.info("Clearing pdp_contacts to prepare for match")
70+
logger.debug("Clearing pdp_contacts to prepare for match")
7171
reset_pdp_contacts_with_unmatched(conn)
7272

73-
logger.info("Computing matches")
73+
logger.debug("Computing automatic matches")
7474
automatic_matches = get_automatic_matches(conn)
75+
logger.debug("Computing manual matches")
7576
manual_matches = get_manual_matches(conn)
7677

7778
match_graph = Graph()
79+
logger.debug("Adding automatic matches to graph")
7880
match_graph.add_edges_from(automatic_matches)
81+
logger.debug("Adding manual matches to graph")
7982
match_graph.add_edges_from(manual_matches)
83+
logger.debug("Processing graph")
8084
match_groups = connected_components(match_graph)
8185

82-
logger.info("Updating pdp_contacts with match ids")
86+
logger.debug("Updating pdp_contacts with match ids")
8387
update_matching_ids(match_groups, conn)
8488

85-
logger.info("Finished flow script run")
89+
logger.debug("Finished flow script run")
8690
job_outcome = "completed"
8791
log_db.log_exec_status(job_id, "flow", "complete", "")
8892

src/server/shifts_importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def validate_import_vs(filename, conn):
130130
# parent will commit. Don't commit here!
131131

132132

133-
logger.info("Total rows: %s Dupes: %s Missing volgistics id: ", str(row_count), str(dupes), str(missing_volgistics_id) )
133+
logger.info("Total rows: %s Dupes: %s Missing volgistics id: %s", str(row_count), str(dupes), str(missing_volgistics_id) )
134134
logger.info("Other integrity exceptions: %s Other exceptions: %s", str(other_exceptions), str(other_integrity) )
135135
wb.close()
136136
return { True : "File imported" }

0 commit comments

Comments
 (0)