Add scheduled job to delete old analytics properties from all user profiles.
Build and Deploy API / build-and-deploy (push) Successful in 1m51s
Details
Build and Deploy API / build-and-deploy (push) Successful in 1m51s
Details
This commit is contained in:
parent
3394869410
commit
1ff3ac5058
|
|
@ -106,6 +106,24 @@ class FileSystemProfileRepository : ProfileRepository {
|
||||||
private string getProfilePath(string name) {
|
private string getProfilePath(string name) {
|
||||||
return buildPath(this.usersDir, username, "profiles", name ~ ".sqlite");
|
return buildPath(this.usersDir, username, "profiles", name ~ ".sqlite");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that applies a given function to ALL profiles of ALL
|
||||||
|
* users.
|
||||||
|
* Params:
|
||||||
|
* fn = The function to execute against all profiles of all users.
|
||||||
|
*/
|
||||||
|
static void doForAllUserProfiles(void function(Profile, ProfileRepository) fn) {
|
||||||
|
import auth.data;
|
||||||
|
import auth.data_impl_fs;
|
||||||
|
UserRepository userRepo = new FileSystemUserRepository();
|
||||||
|
foreach (user; userRepo.findAll()) {
|
||||||
|
ProfileRepository profileRepo = new FileSystemProfileRepository(user.username);
|
||||||
|
foreach (profile; profileRepo.findAll()) {
|
||||||
|
fn(profile, profileRepo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SqlitePropertiesRepository : PropertiesRepository {
|
class SqlitePropertiesRepository : PropertiesRepository {
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,37 @@ import slf4d;
|
||||||
|
|
||||||
void startScheduledJobs() {
|
void startScheduledJobs() {
|
||||||
JobSchedule analyticsSchedule = new FixedIntervalSchedule(
|
JobSchedule analyticsSchedule = new FixedIntervalSchedule(
|
||||||
hours(1),
|
days(1),
|
||||||
Clock.currTime(UTC()) + seconds(5)
|
Clock.currTime(UTC()) + seconds(5)
|
||||||
);
|
);
|
||||||
|
|
||||||
JobScheduler jobScheduler = new TaskPoolScheduler();
|
JobScheduler jobScheduler = new TaskPoolScheduler();
|
||||||
// jobScheduler.addJob(() {
|
jobScheduler.addJob(() {
|
||||||
// info("Computing account balance time series analytics for all users...");
|
// Clear old analytics data from profiles.
|
||||||
// info("Done computing analytics!");
|
import profile.data;
|
||||||
// }, analyticsSchedule);
|
import profile.data_impl_sqlite;
|
||||||
// jobScheduler.start();
|
import profile.model;
|
||||||
|
FileSystemProfileRepository.doForAllUserProfiles(
|
||||||
|
(Profile profile, ProfileRepository profileRepo) {
|
||||||
|
ProfileDataSource ds = profileRepo.getDataSource(profile);
|
||||||
|
auto props = ds.getPropertiesRepository().findAll();
|
||||||
|
bool shouldDelete = false;
|
||||||
|
foreach (prop; props) {
|
||||||
|
import std.string : startsWith;
|
||||||
|
if (startsWith(prop.property, "analytics")) {
|
||||||
|
shouldDelete = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shouldDelete) {
|
||||||
|
ds.getPropertiesRepository().deleteAllByPrefix("analytics");
|
||||||
|
infoF!"Deleted all old \"analytics\" properties for user %s profile %s."(
|
||||||
|
profile.username, profile.name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}, analyticsSchedule);
|
||||||
|
jobScheduler.start();
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue