# Customization Guide

SilentCronX exposes customization at the scheduler, job, queue, storage, logger, and worker levels.

## Scheduler Options

```ts
const cron = createSilentCronX({
  timezone: "Asia/Kolkata",
  maxWorkers: 4,
  maxConcurrency: 50,
  defaultTimeout: 30_000,
  preventOverlapping: true,
  lockTimeout: 30_000,
  maxPayloadBytes: 1024 * 1024,
  logger: console,
  storage: "memory",
  debug: false,
  eventHistoryLimit: 250,
});
```

## Job Options

- `payload`: serializable data passed to the handler.
- `timeout`: per-job timeout in milliseconds.
- `retry`: attempts, delay, and backoff strategy.
- `priority`: higher priority queue jobs run first.
- `preventOverlap`: avoid running the same named critical job concurrently.
- `enabled`: register a cron or interval job in paused state.

## Retry Options

```ts
retry: {
  attempts: 3,
  delayMs: 1000,
  backoff: "exponential",
  maxDelayMs: 10_000,
  jitter: true,
  shouldRetry: (error) => error instanceof Error,
}
```

Backoff options: `fixed`, `linear`, `exponential`.

`jitter` can be `true` for 20 percent variance, or a number from `0` to `1` for custom variance.

## Queue Controls

```ts
cron.queue("emails", {
  concurrency: 5,
  maxSize: 2000,
  paused: false,
  rateLimit: { limit: 500, intervalMs: 60_000 },
  processor: async ({ payload }) => {
    console.log(payload);
  },
});

cron.pauseQueue("emails");
cron.resumeQueue("emails");
const stats = cron.getQueueStats("emails");
const removedPendingJobs = await cron.clearQueue("emails");
```

Use queue stats to build admin panels, dashboards, or internal monitoring endpoints.

## Event History

```ts
const allEvents = cron.getEventHistory();
const failures = cron.getEventHistory("job:failed");
cron.clearEventHistory();
```

## Custom Logger

```ts
const logger = {
  info: (...args: unknown[]) => console.log("[jobs]", ...args),
  warn: (...args: unknown[]) => console.warn("[jobs]", ...args),
  error: (...args: unknown[]) => console.error("[jobs]", ...args),
  debug: (...args: unknown[]) => console.debug("[jobs]", ...args),
};
```

## Custom Storage

Implement the `StorageAdapter` interface when you need Redis, Postgres, MySQL, MongoDB, or any internal company storage.

```ts
import type { StorageAdapter } from "silent-cronx";

export const storage: StorageAdapter = {
  async saveJob(job) {},
  async updateJob(jobId, patch) {},
  async getJob(jobId) {
    return null;
  },
  async listJobs(filter) {
    return [];
  },
  async deleteJob(jobId) {},
  async acquireLock(lockKey, ttlMs) {
    return true;
  },
  async releaseLock(lockKey) {},
};
```

## Client Customization

React, React Native, Android, and other clients can customize the user experience while keeping SilentCronX on the backend. Expose routes such as:

- `POST /api/jobs/report`
- `GET /api/jobs/:id`
- `GET /api/jobs/health`
- `POST /api/jobs/:id/cancel`

See `examples/live-demo` for a simple backend connection.
