mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-13 01:58:44 +02:00
[PM-6426] Implementing eventUploadInterval using TaskScheduler
This commit is contained in:
parent
752df0612d
commit
2ebce58f28
@ -749,6 +749,7 @@ export default class MainBackground {
|
||||
this.stateProvider,
|
||||
this.logService,
|
||||
this.accountService,
|
||||
this.taskSchedulerService,
|
||||
);
|
||||
this.eventCollectionService = new EventCollectionService(
|
||||
this.cipherService,
|
||||
|
@ -17,13 +17,18 @@ import {
|
||||
} from "../../platform/background/service-factories/log-service.factory";
|
||||
import { stateProviderFactory } from "../../platform/background/service-factories/state-provider.factory";
|
||||
import { StateServiceInitOptions } from "../../platform/background/service-factories/state-service.factory";
|
||||
import {
|
||||
taskSchedulerServiceFactory,
|
||||
TaskSchedulerServiceInitOptions,
|
||||
} from "../../platform/background/service-factories/task-scheduler-service.factory";
|
||||
|
||||
type EventUploadServiceOptions = FactoryOptions;
|
||||
|
||||
export type EventUploadServiceInitOptions = EventUploadServiceOptions &
|
||||
ApiServiceInitOptions &
|
||||
StateServiceInitOptions &
|
||||
LogServiceInitOptions;
|
||||
LogServiceInitOptions &
|
||||
TaskSchedulerServiceInitOptions;
|
||||
|
||||
export function eventUploadServiceFactory(
|
||||
cache: { eventUploadService?: AbstractEventUploadService } & CachedServices,
|
||||
@ -39,6 +44,7 @@ export function eventUploadServiceFactory(
|
||||
await stateProviderFactory(cache, opts),
|
||||
await logServiceFactory(cache, opts),
|
||||
await accountServiceFactory(cache, opts),
|
||||
await taskSchedulerServiceFactory(cache, opts),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -737,7 +737,13 @@ const safeProviders: SafeProvider[] = [
|
||||
safeProvider({
|
||||
provide: EventUploadServiceAbstraction,
|
||||
useClass: EventUploadService,
|
||||
deps: [ApiServiceAbstraction, StateProvider, LogService, AccountServiceAbstraction],
|
||||
deps: [
|
||||
ApiServiceAbstraction,
|
||||
StateProvider,
|
||||
LogService,
|
||||
AccountServiceAbstraction,
|
||||
TaskSchedulerService,
|
||||
],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: EventCollectionServiceAbstraction,
|
||||
|
@ -7,6 +7,8 @@ import { AuthenticationStatus } from "../../auth/enums/authentication-status";
|
||||
import { EventData } from "../../models/data/event.data";
|
||||
import { EventRequest } from "../../models/request/event.request";
|
||||
import { LogService } from "../../platform/abstractions/log.service";
|
||||
import { TaskSchedulerService } from "../../platform/abstractions/task-scheduler.service";
|
||||
import { ScheduledTaskNames } from "../../platform/enums/scheduled-task-name.enum";
|
||||
import { StateProvider } from "../../platform/state";
|
||||
import { UserId } from "../../types/guid";
|
||||
|
||||
@ -19,6 +21,7 @@ export class EventUploadService implements EventUploadServiceAbstraction {
|
||||
private stateProvider: StateProvider,
|
||||
private logService: LogService,
|
||||
private accountService: AccountService,
|
||||
private taskSchedulerService: TaskSchedulerService,
|
||||
) {}
|
||||
|
||||
init(checkOnInterval: boolean) {
|
||||
@ -28,10 +31,12 @@ export class EventUploadService implements EventUploadServiceAbstraction {
|
||||
|
||||
this.inited = true;
|
||||
if (checkOnInterval) {
|
||||
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.uploadEvents();
|
||||
setInterval(() => this.uploadEvents(), 60 * 1000); // check every 60 seconds
|
||||
void this.uploadEvents();
|
||||
void this.taskSchedulerService.setInterval(
|
||||
() => this.uploadEvents(),
|
||||
60 * 1000, // check every 60 seconds
|
||||
ScheduledTaskNames.eventUploadsInterval,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user