Challenge Overview
Challenge Objectives
The main goal of this challenge is to add two new properties to the “project” model in Topcoder Project Service to track the latest activity related to the project.
Project Background
TC Project Service serves project list for Topcode Connect and lets us sort project by the “Last Updated” column:
Currently, project’s “Last Updated” date is only updated on changes happen inside “project” model. But there are several related entities like project phases, timelines, milestones, posts and files (attachments) which we want to be taken into account when we sort project by the latest activity date.
So we will add two properties to the project model which will track this more general last activity time.
Technology Stack
-
Node.js
-
PostgreSQL
-
Kafka
Code access
All the work will be done in TC Project Service repo https://github.com/topcoder-platform/tc-project-service dev branch commit #4f0ce2e637f43dc29e3a5460c3e7bc06be99449c.
Individual requirements
Implementation overview
To update time of the last activity in the project model, we have to know when related entities like project phases, timelines, milestones, posts and files (attachments) were updated. While most of them are handled inside TC Project Service, “posts” are handled by different codebase in TC Message Service. To know when “posts” are updated we have to subscribe to KAFKA events fired by TC Message Service.
To unify the approach, when some entities in TC Project Service are changed we will also fire KAFKA events. At the end we will subscribe to events from both TC Message Service and TC Project Service and update the last activity properties of the project when these events happen.
All the requirements from point 1 to point 4 are MAJOR, and will contribute to reviewing score any requirement missed will lead to points deduction.
1. Fire new KAFKA events
Project Service already fires several KAFKA events. We have to add some new event calls with the following KAFKA topics and conditions to be fired:
-
PROJECT_UPDATED (notifications.connect.project.updated)
+ Project updated with one of the following properties changed: status, details, name, description, bookmarks -
PROJECT_FILES_UPDATED (notifications.connect.project.files.updated)
+ File (attachment) was added, updated or removed. -
PROJECT_TEAM_UPDATED (notifications.connect.project.team.updated)
+ Project member was added, updated or removed. -
PROJECT_PLAN_UPDATED (notifications.connect.project.plan.updated)
We already have event PROJECT_PLAN_MODIFIED with topic notifications.connect.project.planModified. It has to be renamed to PROJECT_PLAN_UPDATED with topic notifications.connect.project.plan.updated. Also, it has to be fired only when one of the conditions described below are met. Now it doesn’t follow these conditions.
+ Phase added or removed.
+ Phase updated with one of the following properties changed: spentBudget, progress, details, status, budget, startDate, duration.
+Timeline updated with one of the following properties changed: startDate, endDate.
+ Milestone was added or removed
+ Milestone was updated with one of the following properties changed: startDate, endDate, duration, details, status, order.
Each of these events have to be fired with the same payload:
{
projectId: project.id,
projectName: project.name,
projectUrl: connectProjectUrl(project.id),
userId: req.authUser.userId,
initiatorUserId: req.authUser.userId,
}
Implementation notes.
-
Important. Each of these events should be fired not more than once per one REST API endpoint call.
-
Please follow the current approach to fire KAFKA using BUS API events. In particular fire them inside /src/events/busApi.js.
2. Add new properties to the “project” model
Properties to add:
-
lastActivityAt: { type: DataTypes.INTEGER, allowNull: false }
-
lastActivityUserId: { type: DataTypes.INTEGER, allowNull: false }
-
These properties has to be initialized for new projects with the project creation time and user who created the project.
-
Make project list sortable by lastAcivityAt, similar to updatedAt, see https://github.com/topcoder-platform/tc-project-service/blob/dev/src/routes/projects/list.js#L287 and https://github.com/topcoder-platform/tc-project-service/blob/dev/src/routes/projects/list-db.js#L104.
-
Adjust src/routes/admin/project-create-index.js to support two new properties.
-
Update any other place related to project model to support these properties.
Create a migration SQL script in /migrations folder which will:
-
add new columns to projects table
-
populate values of lastActivityAt by updatedAt and lastActivityUserId by updatedBy
-
make these columns NOT NULL
3. Update project activity properties on related events
Project service has to listen to the following KAFKA topics.
Events which are fired in project service (added in the first step):
-
notifications.connect.project.updated
-
notifications.connect.project.files.updated
-
notifications.connect.project.team.updated
-
notifications.connect.project.plan.updated
Events which come from TC Message Service:
-
notifications.connect.project.topic.created
-
notifications.connect.project.topic.updated
-
notifications.connect.project.post.created
-
notifications.connect.project.post.edited
When any of these events happen we have to
-
find project by projectId from the event payload
-
update lastActivityAt by the current time
-
update lastActivityUserId by the initiatorUserId from the event payload
-
reindex the project in ElasticSearch
Example of how to listen to KAFKA topics can be found here https://github.com/topcoder-platform/tc-notifications/blob/dev/src/app.js
4. Lint and unit tests
-
Linter and unit tests should be successfully passed.
-
Validate new changes with unit tests. We are not expecting particular coverage level but instead would like to have valuable tests for essential workflows. In particular please validate new KAFKA events from the first task:
+ They are fired not more than once per REST API calls
+ They are fired only when described conditions for them are met
If you have any doubts or questions do not hesitate to ask in the challenge forum.
Deployment guide and validation document
Final Submission Guidelines
-
Patch to the dev branch
-
Updated documentation
-
Verification guide