Added sample scheduled job, cached repositories.
This commit is contained in:
parent
185cf706a7
commit
2b85abcfae
|
|
@ -1,6 +1,8 @@
|
||||||
import handy_http_transport;
|
import handy_http_transport;
|
||||||
import slf4d;
|
import slf4d;
|
||||||
import slf4d.default_provider;
|
import slf4d.default_provider;
|
||||||
|
import scheduled;
|
||||||
|
import std.datetime;
|
||||||
|
|
||||||
import api_mapping;
|
import api_mapping;
|
||||||
import util.config;
|
import util.config;
|
||||||
|
|
@ -12,6 +14,13 @@ void main() {
|
||||||
configureLoggingProvider(provider);
|
configureLoggingProvider(provider);
|
||||||
infoF!"Loaded app config: port = %d, webOrigin = %s"(config.port, config.webOrigin);
|
infoF!"Loaded app config: port = %d, webOrigin = %s"(config.port, config.webOrigin);
|
||||||
|
|
||||||
|
// Start scheduled tasks in a separate thread:
|
||||||
|
JobScheduler jobScheduler = new TaskPoolScheduler();
|
||||||
|
jobScheduler.addJob(() {
|
||||||
|
info("Executing scheduled job with fixed interval.");
|
||||||
|
}, new FixedIntervalSchedule(minutes(1)));
|
||||||
|
jobScheduler.start();
|
||||||
|
|
||||||
Http1TransportConfig transportConfig = defaultConfig();
|
Http1TransportConfig transportConfig = defaultConfig();
|
||||||
transportConfig.port = config.port;
|
transportConfig.port = config.port;
|
||||||
HttpTransport transport = new TaskPoolHttp1Transport(mapApiHandlers(config.webOrigin), transportConfig);
|
HttpTransport transport = new TaskPoolHttp1Transport(mapApiHandlers(config.webOrigin), transportConfig);
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,17 @@ class SqliteProfileDataSource : ProfileDataSource {
|
||||||
private const string dbPath;
|
private const string dbPath;
|
||||||
Database db;
|
Database db;
|
||||||
|
|
||||||
|
// Cached versions of all the repositories:
|
||||||
|
PropertiesRepository propertiesRepo;
|
||||||
|
AttachmentRepository attachmentRepo;
|
||||||
|
AccountRepository accountRepo;
|
||||||
|
AccountJournalEntryRepository accountJournalEntryRepo;
|
||||||
|
AccountValueRecordRepository accountValueRecordRepo;
|
||||||
|
TransactionVendorRepository transactionVendorRepo;
|
||||||
|
TransactionCategoryRepository transactionCategoryRepo;
|
||||||
|
TransactionTagRepository transactionTagRepo;
|
||||||
|
TransactionRepository transactionRepo;
|
||||||
|
|
||||||
this(string path) {
|
this(string path) {
|
||||||
this.dbPath = path;
|
this.dbPath = path;
|
||||||
import std.file : exists;
|
import std.file : exists;
|
||||||
|
|
@ -169,40 +180,67 @@ class SqliteProfileDataSource : ProfileDataSource {
|
||||||
migrateSchema();
|
migrateSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertiesRepository getPropertiesRepository() return scope {
|
PropertiesRepository getPropertiesRepository() {
|
||||||
return new SqlitePropertiesRepository(db);
|
if (propertiesRepo is null) {
|
||||||
|
propertiesRepo = new SqlitePropertiesRepository(db);
|
||||||
|
}
|
||||||
|
return propertiesRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachmentRepository getAttachmentRepository() return scope {
|
AttachmentRepository getAttachmentRepository() {
|
||||||
return new SqliteAttachmentRepository(db);
|
if (attachmentRepo is null) {
|
||||||
|
attachmentRepo = new SqliteAttachmentRepository(db);
|
||||||
|
}
|
||||||
|
return attachmentRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountRepository getAccountRepository() return scope {
|
AccountRepository getAccountRepository() {
|
||||||
return new SqliteAccountRepository(db);
|
if (accountRepo is null) {
|
||||||
|
accountRepo = new SqliteAccountRepository(db);
|
||||||
|
}
|
||||||
|
return accountRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountJournalEntryRepository getAccountJournalEntryRepository() return scope {
|
AccountJournalEntryRepository getAccountJournalEntryRepository() {
|
||||||
return new SqliteAccountJournalEntryRepository(db);
|
if (accountJournalEntryRepo is null) {
|
||||||
|
accountJournalEntryRepo = new SqliteAccountJournalEntryRepository(db);
|
||||||
|
}
|
||||||
|
return accountJournalEntryRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountValueRecordRepository getAccountValueRecordRepository() return scope {
|
AccountValueRecordRepository getAccountValueRecordRepository() {
|
||||||
return new SqliteAccountValueRecordRepository(db);
|
if (accountValueRecordRepo is null) {
|
||||||
|
accountValueRecordRepo = new SqliteAccountValueRecordRepository(db);
|
||||||
|
}
|
||||||
|
return accountValueRecordRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionVendorRepository getTransactionVendorRepository() return scope {
|
TransactionVendorRepository getTransactionVendorRepository() {
|
||||||
return new SqliteTransactionVendorRepository(db);
|
if (transactionVendorRepo is null) {
|
||||||
|
transactionVendorRepo = new SqliteTransactionVendorRepository(db);
|
||||||
|
}
|
||||||
|
return transactionVendorRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionCategoryRepository getTransactionCategoryRepository() return scope {
|
TransactionCategoryRepository getTransactionCategoryRepository() {
|
||||||
return new SqliteTransactionCategoryRepository(db);
|
if (transactionCategoryRepo is null) {
|
||||||
|
transactionCategoryRepo = new SqliteTransactionCategoryRepository(db);
|
||||||
|
}
|
||||||
|
return transactionCategoryRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionTagRepository getTransactionTagRepository() return scope {
|
TransactionTagRepository getTransactionTagRepository() {
|
||||||
return new SqliteTransactionTagRepository(db);
|
if (transactionTagRepo is null) {
|
||||||
|
transactionTagRepo = new SqliteTransactionTagRepository(db);
|
||||||
|
}
|
||||||
|
return transactionTagRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionRepository getTransactionRepository() return scope {
|
TransactionRepository getTransactionRepository() {
|
||||||
return new SqliteTransactionRepository(db);
|
if (transactionRepo is null) {
|
||||||
|
transactionRepo = new SqliteTransactionRepository(db);
|
||||||
|
}
|
||||||
|
return transactionRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void doTransaction(void delegate () dg) {
|
void doTransaction(void delegate () dg) {
|
||||||
|
|
@ -211,7 +249,7 @@ class SqliteProfileDataSource : ProfileDataSource {
|
||||||
|
|
||||||
private void migrateSchema() {
|
private void migrateSchema() {
|
||||||
import std.conv;
|
import std.conv;
|
||||||
PropertiesRepository propsRepo = new SqlitePropertiesRepository(this.db);
|
PropertiesRepository propsRepo = getPropertiesRepository();
|
||||||
uint currentVersion;
|
uint currentVersion;
|
||||||
try {
|
try {
|
||||||
currentVersion = propsRepo.findProperty("database-schema-version")
|
currentVersion = propsRepo.findProperty("database-schema-version")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue