---
id: "wrap-a-function"
type: "guide"
title: "Wrap an existing function"
summary: "Turn a TypeScript function into a scheduled managed service with one defineServixService call."
why: "Wrapping keeps the function reusable and testable while Servix owns scheduling, logs, and health."
audiences: ["developers"]
prerequisites: ["service-shell"]
related: ["wrap-a-cli-command", "wrap-a-listener"]
---
# Wrap an existing function

1. Keep your existing function untouched:

```ts
export async function runMongoBackup(config: MongoBackupConfig) {
  // existing logic
}
```

2. Add a `servix.service.ts` wrapper:

```ts
import { defineServixService } from "@x12i/servix";
import { runMongoBackup } from "./runMongoBackup";

export default defineServixService({
  name: "mongo-backup",
  workers: [
    {
      id: "hourly-backup",
      type: "proactive",
      schedule: { mode: "interval", everyMs: 60 * 60 * 1000 },
      async execute(ctx) {
        await runMongoBackup(ctx.config);
      }
    }
  ]
});
```

3. Install and start:

```bash
servix install ./dist/servix.service.js
servix start mongo-backup
```

> Proactive workers are typed but not executed yet in v0.1 — listener workers are fully supported.