<commit_before>import raven from 'raven'

import config from 'src/config'
import ChatClient from 'src/server/clients/ChatClient'
import {getQueue} from 'src/server/util/queue'
import {getChapterById} from 'src/server/db/chapter'
import {findProjectBySurveyId} from 'src/server/db/project'
import {getSurveyById, recordSurveyCompletedBy, surveyWasCompletedBy} from 'src/server/db/survey'
import sendPlayerStatsSummaries from 'src/server/actions/sendPlayerStatsSummaries'
import updateProjectStats from 'src/server/actions/updateProjectStats'

const sentry = new raven.Client(config.server.sentryDSN)

const PROJECT_SURVEY_TYPES = {
  RETROSPECTIVE: 'retrospective',
  REVIEW: 'review',
}

export function start() {
  const surveyResponseSubmitted = getQueue('surveyResponseSubmitted')
  surveyResponseSubmitted.process(({data: event}) =>
    processSurveyResponseSubmitted(event)
      .catch(err => {
        console.error(err)
        sentry.captureException(err)
      })
  )
}

export async function processSurveyResponseSubmitted(event, chatClient = new ChatClient()) {
  if (!await surveyWasCompletedBy(event.surveyId, event.respondentId)) {
    return
  }

  let project
  try {
    project = await findProjectBySurveyId(event.surveyId)<commit_msg>`surveyResponseSubmitted` worker refactored to use `processJobs`<commit_after>import ChatClient from 'src/server/clients/ChatClient'
import {processJobs} from 'src/server/util/queue'
import {getChapterById} from 'src/server/db/chapter'
import {findProjectBySurveyId} from 'src/server/db/project'
import {getSurveyById, recordSurveyCompletedBy, surveyWasCompletedBy} from 'src/server/db/survey'
import sendPlayerStatsSummaries from 'src/server/actions/sendPlayerStatsSummaries'
import updateProjectStats from 'src/server/actions/updateProjectStats'

const PROJECT_SURVEY_TYPES = {
  RETROSPECTIVE: 'retrospective',
  REVIEW: 'review',
}

export function start() {
  processJobs('surveyResponseSubmitted', processSurveyResponseSubmitted)
}

export async function processSurveyResponseSubmitted(event, chatClient = new ChatClient()) {
  console.log(`Survey [${event.surveyId}] Response Submitted By [${event.respondentId}]`)

  if (!await surveyWasCompletedBy(event.surveyId, event.respondentId)) {
    return
  }

  let project
  try {
    project = await findProjectBySurveyId(event.surveyId)
{'fraction_non_alphanumeric': 0.10106609808102346, 'fraction_numerical': 0.0, 'mean_word_length': 6.152439024390244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5095793', 'n_tokens_mistral': 729, 'n_tokens_neox': 712, 'n_words': 147}