Add members activity tracker worker

What does this MR do and why?

This MR adds GitlabSubscriptions::Members::RecordLastActivityWorker It is used to subscribe to ::Users::ActivityEvent and record the user activity in relation to namespace membership.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Run gdk restart rails-background-jobs redis

  2. Setup the machine: gdk rails c

    # enable feature flag
    ::Feature.enable(:track_member_activity) # true
    # clear existing records, if any
    GitlabSubscriptions::SeatAssignment.destroy_all
  3. Create a new root Group, with a Project

  4. Perform an action in the group or the project, e.g. viewing the project repo

  5. Check that GitlabSubscriptions::SeatAssignment record has been created

    GitlabSubscriptions::SeatAssignment.all # should return new records created
    # Or,
    namespace = Group.last # group created
    user = User.find(ID) # ID: your user id
    seat_assignment = GitlabSubscriptions::SeatAssignment.find_by_namespace_and_user(namespace, user) # returns record to the new group
  6. Re-perform the same action, and there should be no change to the seat_assignment record's last_activity_on as we only track once per day:

      seat_assignment.reload.last_activity_on # should be the same as above
  7. You can visit any other existing projects in your local gdk and see the GitlabSubscriptions::SeatAssignment records being created.

You can optionally tail the sidekiq logs and view the activity event being processed by sidekiq:

tail -F log/sidekiq.log | grep -F --line-buffered 'GitlabSubscriptions::Members::RecordLastActivityWorker'

Related to #461338 (closed)

Edited by Bishwa Hang Rai

Merge request reports

Loading