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:
- Scheduled Task: A cron job that runs every 15 minutes to check and update the
letzterBesuchfield for online users. - Update Logic: The update logic checks if a user's
letzterBesuchfield 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 theletzterBesuchfield 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
- The service is initialized when the server starts.
- Every 15 minutes, the service checks all users in the
UserOnlineListecollection. - For each online user, it checks if their
letzterBesuchfield needs to be updated. - If an update is needed, it sets the
letzterBesuchfield to the current Berlin time (UTC+2) and setsistOnlinetotrue.
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:
- The
updateUserData.jscontroller already updates theletzterBesuchfield when user data is updated. - The
muc4taxiUserModel.jspre-save hook updates theletzterBesuchfield when a user document is saved. - The new scheduled task ensures that the
letzterBesuchfield 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:
- Make sure the MongoDB connection is working correctly.
- Check the server logs for any errors related to the scheduled task.
- Verify that the
UserOnlineListecollection contains the expected users. - Ensure that the
Muc4taxiUsercollection contains the corresponding user records.