Resolve "Update usage metrics: Rotating Ids"
Closes #1024
Import these two modules for testing:
import {
ConsoleAsUsageLoggingEndpointModule,
ExampleUsageLoggingJobsModule
} from '@rcc/examples'
You should see logs on the console every 5 seconds. (50x for each of two jobs). job-1 has no id (aka will use a new random id every time). job-2 has a daily rotating id which will stay the same for the day.
If you have do-not-track enables in your browser, it will tell you on the console. switch it of temporarily to see the logging data. (No worries nothing will be posted to matomo in dev environment)
There two large chunks here:
- Addition of the
RccRotatingIdService
and its unit tests - Integration of the
RccRotatingIdService
into and restructuring ofRccUsageLoggingService
, plus unit tests for the issues I had.
The main trouble in RccUsageLoggingService
stems from timing and permissions: The service starts out with logging in general and logging for specific jobs in particular beeing not allowed. RccUsageLoggingSettingsService
will quickly allow some of the jobs to log and enable logging globally if that's what the settings say, but it will take a few milliseconds to load that info from the storage. In the meantime Logging jobs, that emit on subscribe can already have emitted. So we have to wait with subscribing until after the jobs are enabled. But jobs can be disabled an re-enabled and we would not want them to keep repeating (and eventually posting) their initial values.
So solution was to wait for the first time both global usage logging and the particular job are enables for the first time and then subscribe, without ever unsubscribing unless the service destroys.
Also the emission of the collected job events now take a tiny bit longer because adding the rotating id is asynchronous. Additionally messing with the timing.