Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plugins/replication/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Replication Plugin

Syncs data from an external source to the StarbaseDB instance at regular intervals.

## Configuration

Enable it in `src/index.ts` by creating a new instance of `ReplicationPlugin`.

```typescript
new ReplicationPlugin(cronPlugin)
```

It uses the `CronPlugin` to schedule the sync task.
20 changes: 20 additions & 0 deletions plugins/replication/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Plugin } from '../../src/index'
import { CronPlugin } from '../cron'

export class ReplicationPlugin implements Plugin {
constructor(private cronPlugin: CronPlugin) {}

async init() {
this.cronPlugin.addJob('replication', '*/5 * * * *', async () => {
console.log('Running replication task...')
// Logic for syncing external data to internal database
try {
const response = await fetch('https://api.example.com/data')
const data = await response.json()
console.log('Data fetched for replication:', data)
} catch (error) {
console.error('Replication failed:', error)
}
})
}
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { QueryLogPlugin } from '../plugins/query-log'
import { StatsPlugin } from '../plugins/stats'
import { CronPlugin } from '../plugins/cron'
import { InterfacePlugin } from '../plugins/interface'

import { ReplicationPlugin } from '../plugins/replication'
export { StarbaseDBDurableObject } from './do'

const DURABLE_OBJECT_ID = 'sql-durable-object'
Expand Down Expand Up @@ -212,7 +212,7 @@ export default {
const interfacePlugin = new InterfacePlugin()

const plugins = [
webSocketPlugin,
webSocketPlugin,new ReplicationPlugin(cronPlugin),
new StudioPlugin({
username: env.STUDIO_USER,
password: env.STUDIO_PASS,
Expand Down