Skip to content

Survey post successful week payment #395

Closed
@maxceem

Description

@maxceem

Context

Project Context

TaaS (Talent as a Service) is Topcoder project which let customers to hire top freelancers for gigs and directly manage the talents.

Challenge Context

In TaaS we have members (ResourceBookings) who are assigned to the customer's Jobs for some period of time. This time is divided into weeks (WorkPeriods) and payments to the ResourceBookings (members) is processed weekly. When the WorkPeriod is fully paid we would like to send a survey to the ResourceBooking to get the feedback about completed week.

Expected Outcome

Send weekly surveys for all completed WorkPeriods in batches.

Challenge Details

Technology Stack

  • Node.js
  • PostgreSQL
  • SurveyMonkey API

Code access

The work in this challenge would be done in the next repositories:

Environment variables necessary to run this service would be shared on the forum.

Individual requirements

Update Models

  • Add field "sendWeeklySurvey" to the model "ResourceBooking" - boolean, required, "true" by default - this field would indicate whether we should send weekly survey to this ResourceBooking or no.
  • Add field "sentSurvey" to the model "WorkPeriod" - boolean, required, "false" by default - this field would indicate whether we've already sent a survey for this WorkPeriod of no.
  • Add field "sentSurveyError" to the model "WorkPeriod" - json(b), optional - it should store the error details if error happened during sending survey in JSON(B) format: { errorCode: XXX, errorMessage: "..." }

Send Surveys

We want to send surveys to the "WorkPeriods" when "WorkPeriod.paymentStatus" becomes "completed". But SurveyMonkey only allows us sending 500 requests per day. If we send survey individually for each WorkPeriod we would exceed this limit very quickly. To overcome this we would like to send surveys in batches for each week. We already implemented this logic in other Topcoder Service and the here is a pseudo-code of the logic. It's very detailed and almost fully solves this task.

General logic:

  • once per day get all the WorkPeriods where "paymentStatus == completed" and "sentSurvey == false" and "sentSurveyError == null" and "ResourceBooking.sendWeeklySurvey == true" (we already have "node-schedule" library which could be used to run code by schedule)
  • send surveys for them, see method "sendSurvey" in the pseudo-code
  • if error happens, then save error details into "sentSurveyError" for each failed WorkPeriod. Include server error message from SurveyMonkey if error happened during API request.

Minimize SurveyMonkey API calls

Provided pseudo-code logic already tries to minimize the number of SurveyMonkey API calls, but we should try to minimize it more if possible. For example, consider the following way:

  • Instead of searching contacts one by one in upsertContactInSurveyMonkey search for all the needed contacts at once using /contacts/bulk
  • After that create not existent contacts at once using the same bulk endpoint.
  • Make sure to retrieve all the pages and respect bulk limits if any.
  • You may also cache some data in-memory like this to avoid duplicate API calls if it helps. No need to over-engineer and create complex cache, simple in-memory cache should be fine as long as we don't store a huge data there.

If there are any other ways to reduce the number of calls, please do it. So after all the optimizations I guess per day we usually would make only 6 calls:

  • create collector for each week (usually we would process only for 1-2 weeks during 1 day) - 2 calls
  • search all the contacts - 1 call
  • create all the missing contacts - 1 call
  • send surveys for each collector (would be 1-2 usually) - 2 calls

Verification Guide

  • Create a verification guide with the specific steps to follow so that reviewers could verify sending surveys logic.
  • Include steps on how to config SurveyMonkey for testing: create account, create master collector, master message, contact list and so on.

General requirements

  • For debugging purposes, each time we call SurveyMonkey API, log the API URL we are calling and how many calls we already did per day. Can store this counter in-memory.
  • Keep separately scheduler logic from the SurveyMonkey API logic, as we are planning to replace SurveyMonkey with something else.
  • As we changed the models:
    • Create a DB migration script inside "migrations" folder which would make any necessary updates to the DB schema.
    • Test, that when we migrate DB from the previous state using "npm run migrate", we get exactly the same DB schema as if we create DB from scratch using command "npm run init-db force".
    • Update mapping definitions for ElasticSearch indexes inside both repositories taas-apis and taas-es-processor.
    • Update taas-es-processor to support these fields.
    • Update Swagger and Postman if needed.
    • Update demo-data so "npm run data:import" and "npm run local:init" work good.
  • Follow the existent code structure.
  • Split code into reusable methods where applicable.
  • Existent unit tests should pass.
  • Lint should pass.

Scorecard Aid

The major requirements are:

  • surveys should be sent as per description only once per WorkPeriod
  • the number of SurveyMonkey API calls should be as minimal as possible (It doesn't matter if it's 5 or 10, but it should not linearly depend on how many WorkPeriods or Users we send survey to. If we send survey for 100 user and we have to make 100 calls - it's not a good approach)
  • Verification Guide is also a major requirement in this challenge

Other requirements could be treated as per scorecard.

What To Submit

  • Submit a zip file which would include:
    • a Git patch with changes you’ve made to the code in our repository.
    • Verification Guide in any text format
  • Additionally, the winner would be required to raise a pull request to the repository after the challenge is completed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions