-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathBinLogReplicator.ts
41 lines (34 loc) · 1.43 KB
/
BinLogReplicator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { replication, storage } from '@powersync/service-core';
import { BinLogReplicationJob } from './BinLogReplicationJob.js';
import { MySQLConnectionManagerFactory } from './MySQLConnectionManagerFactory.js';
import { MySQLModule } from '../module/MySQLModule.js';
export interface BinLogReplicatorOptions extends replication.AbstractReplicatorOptions {
connectionFactory: MySQLConnectionManagerFactory;
}
export class BinLogReplicator extends replication.AbstractReplicator<BinLogReplicationJob> {
private readonly connectionFactory: MySQLConnectionManagerFactory;
constructor(options: BinLogReplicatorOptions) {
super(options);
this.connectionFactory = options.connectionFactory;
}
createJob(options: replication.CreateJobOptions): BinLogReplicationJob {
return new BinLogReplicationJob({
id: this.createJobId(options.storage.group_id),
storage: options.storage,
metrics: this.metrics,
lock: options.lock,
connectionFactory: this.connectionFactory,
rateLimiter: this.rateLimiter
});
}
async cleanUp(syncRulesStorage: storage.SyncRulesBucketStorage): Promise<void> {
// The MySQL module does not create anything which requires cleanup on the MySQL server.
}
async stop(): Promise<void> {
await super.stop();
await this.connectionFactory.shutdown();
}
async testConnection() {
return await MySQLModule.testConnection(this.connectionFactory.connectionConfig);
}
}