2nd Brain

README

/home/darth/Documents/moltbotShare/aktuell_27.11/server/services/user/README.md

Online User Timestamp Update Service

This service ensures that the letzterBesuch field is updated for online users at least once a day and then every 60 minutes while they remain online.

Implementation Details

The service consists of the following components:

  1. Scheduled Task: A cron job that runs every 15 minutes to check and update the letzterBesuch field for online users.
  2. Update Logic: The update logic checks if a user's letzterBesuch field needs to be updated based on the following criteria:
    • If the last visit was on a different day
    • If the last visit was more than 60 minutes ago

Files

  • updateOnlineStatus.js: Contains the main logic for updating the letzterBesuch field for online users.
  • ../../../scripts/testUpdateOnlineUsers.js: A test script to manually trigger the update function.
  • ../../../scripts/forceUpdateOnlineUsers.js: A script to force update all online users regardless of their last update time.

How It Works

  1. The service is initialized when the server starts.
  2. Every 15 minutes, the service checks all users in the UserOnlineListe collection.
  3. For each online user, it checks if their letzterBesuch field needs to be updated.
  4. If an update is needed, it sets the letzterBesuch field to the current Berlin time (UTC+2) and sets istOnline to true.

Manual Testing

You can manually test the service using the following scripts:

# Test the update function (only updates if needed)
node scripts/testUpdateOnlineUsers.js

# Force update all online users regardless of their last update time
node scripts/forceUpdateOnlineUsers.js

Integration with Existing Code

The service is integrated with the existing codebase in the following ways:

  1. The updateUserData.js controller already updates the letzterBesuch field when user data is updated.
  2. The muc4taxiUserModel.js pre-save hook updates the letzterBesuch field when a user document is saved.
  3. The new scheduled task ensures that the letzterBesuch field is updated at least once a day and then every 60 minutes while a user is online.

Troubleshooting

If you encounter any issues with the service, check the following:

  1. Make sure the MongoDB connection is working correctly.
  2. Check the server logs for any errors related to the scheduled task.
  3. Verify that the UserOnlineListe collection contains the expected users.
  4. Ensure that the Muc4taxiUser collection contains the corresponding user records.
Attachments
Noch keine.