Skip to content

Commit

Permalink
Remove extraneous filter and add logging for autostaffing (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcua committed Jun 29, 2021
1 parent 903e4ba commit ea186e9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions orchestra/communication/staffing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import json
import logging

from annoying.functions import get_object_or_None
from collections import defaultdict
from datetime import timedelta
Expand Down Expand Up @@ -32,6 +35,8 @@
from orchestra.utils.task_lifecycle import is_worker_certified_for_task
from orchestra.utils.task_lifecycle import reassign_assignment

logger = logging.getLogger(__name__)


@transaction.atomic
def handle_staffing_response(worker, staffing_request_inquiry_id,
Expand Down Expand Up @@ -143,9 +148,6 @@ def address_staffing_requests(
cutoff_datetime = timezone.now() - frequency
requests = _exclude_inactive_staffbot_requests(
StaffBotRequest.objects
.filter(status__in=[
StaffBotRequest.Status.SENDING_INQUIRIES.value,
StaffBotRequest.Status.DONE_SENDING_INQUIRIES.value])
.filter(Q(last_inquiry_sent__isnull=True) |
Q(last_inquiry_sent__lte=cutoff_datetime))
.order_by('-task__project__priority', 'created_at'))
Expand Down Expand Up @@ -236,6 +238,7 @@ def _attempt_to_automatically_staff(staffbot, request, worker_certifications):
CommunicationPreference.CommunicationType.NEW_TASK_AVAILABLE.value)
previously_opted_in_method = (
StaffingRequestInquiry.CommunicationMethod.PREVIOUSLY_OPTED_IN.value)
worker = None
for certification in worker_certifications:
worker = certification.worker
if worker.id in attempted_workers:
Expand All @@ -255,6 +258,16 @@ def _attempt_to_automatically_staff(staffbot, request, worker_certifications):
worker, staffing_request_inquiry.id, is_available=True)
successfully_staffed = True
break
logger.info('Autostaff attempt: %s', json.dumps({
'successfully_staffed': successfully_staffed,
'attempted_workers': list(attempted_workers),
'most_recent_worker': str(worker) if worker else None,
'most_recent_worker_id': worker.id if worker else None,
'staffing_request': str(request),
'staffing_request_id': request.id,
'task': str(request.task),
'task_id': request.task.id
}))
return successfully_staffed


Expand Down

0 comments on commit ea186e9

Please sign in to comment.