> ## Documentation Index
> Fetch the complete documentation index at: https://botmesh.afaya.com.co/llms.txt
> Use this file to discover all available pages before exploring further.

# MemoryScheduleStore

> Class exported by @botmesh/core/spi.

Defined in: [scheduler/ScheduleStore.ts:172](https://github.com/andresayac/botmesh/blob/main/packages/core/src/scheduler/ScheduleStore.ts#L172)

Reference, in-process [ScheduleStore](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore.md). Nothing survives the process.

## Implements

* [`ScheduleStore`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore)

## Constructors

### Constructor

```ts theme={null}
new MemoryScheduleStore(): MemoryScheduleStore;
```

#### Returns

`MemoryScheduleStore`

## Methods

### get()

```ts theme={null}
get(id): Promise<ScheduleRecord | null>;
```

Defined in: [scheduler/ScheduleStore.ts:177](https://github.com/andresayac/botmesh/blob/main/packages/core/src/scheduler/ScheduleStore.ts#L177)

#### Parameters

| Parameter | Type |
| - | - |
| `id` | `string` |

#### Returns

`Promise`\<[`ScheduleRecord`](https://botmesh.afaya.com.co/api/core/spi/interfaces/ScheduleRecord) | `null`>

#### Implementation of

[`ScheduleStore`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore).[`get`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore#get)

***

### register()

```ts theme={null}
register(rec, now): Promise<ScheduleRecord>;
```

Defined in: [scheduler/ScheduleStore.ts:182](https://github.com/andresayac/botmesh/blob/main/packages/core/src/scheduler/ScheduleStore.ts#L182)

Insert the task if absent. If it exists with the same `kind` and `spec`, keep it
untouched (that is how a restart keeps its `nextRunAt`); if either differs, overwrite
`kind`, `spec` and `nextRunAt` with the given ones (the fencing token is kept). Returns
the stored record.

#### Parameters

| Parameter | Type |
| - | - |
| `rec` | `Pick`\<[`ScheduleRecord`](https://botmesh.afaya.com.co/api/core/spi/interfaces/ScheduleRecord), `"id"` \| `"kind"` \| `"spec"` \| `"nextRunAt"`> |
| `now` | `number` |

#### Returns

`Promise`\<[`ScheduleRecord`](https://botmesh.afaya.com.co/api/core/spi/interfaces/ScheduleRecord)>

#### Implementation of

[`ScheduleStore`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore).[`register`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore#register)

***

### claimDue()

```ts theme={null}
claimDue(
   id, 
   owner, 
   now, 
   leaseMs
): Promise<ClaimResult | null>;
```

Defined in: [scheduler/ScheduleStore.ts:199](https://github.com/andresayac/botmesh/blob/main/packages/core/src/scheduler/ScheduleStore.ts#L199)

Atomic claim: succeeds only when `nextRunAt !== null && nextRunAt <= now` and the
record has no live lease (`leaseUntil` absent or `<= now`). Then it sets
`leaseOwner = owner`, `leaseUntil = now + leaseMs` and increments `fencingToken`.
Returns `null` otherwise (not due, leased elsewhere, or unknown id).

#### Parameters

| Parameter | Type |
| - | - |
| `id` | `string` |
| `owner` | `string` |
| `now` | `number` |
| `leaseMs` | `number` |

#### Returns

`Promise`\<[`ClaimResult`](https://botmesh.afaya.com.co/api/core/spi/interfaces/ClaimResult) | `null`>

#### Implementation of

[`ScheduleStore`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore).[`claimDue`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore#claimdue)

***

### renew()

```ts theme={null}
renew(
   id, 
   fencingToken, 
   leaseUntil
): Promise<boolean>;
```

Defined in: [scheduler/ScheduleStore.ts:209](https://github.com/andresayac/botmesh/blob/main/packages/core/src/scheduler/ScheduleStore.ts#L209)

Set `leaseUntil` only if `fencingToken` still matches; `false` means the lease was lost.

#### Parameters

| Parameter | Type |
| - | - |
| `id` | `string` |
| `fencingToken` | `number` |
| `leaseUntil` | `number` |

#### Returns

`Promise`\<`boolean`>

#### Implementation of

[`ScheduleStore`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore).[`renew`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore#renew)

***

### complete()

```ts theme={null}
complete(
   id, 
   fencingToken, 
   patch, 
   now
): Promise<boolean>;
```

Defined in: [scheduler/ScheduleStore.ts:216](https://github.com/andresayac/botmesh/blob/main/packages/core/src/scheduler/ScheduleStore.ts#L216)

Commit an occurrence only if `fencingToken` still matches: write the patch, clear the
lease and set `updatedAt = now`. `false` when stale (claimed again since) or deleted.

#### Parameters

| Parameter | Type |
| - | - |
| `id` | `string` |
| `fencingToken` | `number` |
| `patch` | [`CompletePatch`](https://botmesh.afaya.com.co/api/core/spi/interfaces/CompletePatch) |
| `now` | `number` |

#### Returns

`Promise`\<`boolean`>

#### Implementation of

[`ScheduleStore`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore).[`complete`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore#complete)

***

### delete()

```ts theme={null}
delete(id): Promise<void>;
```

Defined in: [scheduler/ScheduleStore.ts:225](https://github.com/andresayac/botmesh/blob/main/packages/core/src/scheduler/ScheduleStore.ts#L225)

Remove the record. The id's fencing token is kept as a high-water mark: a later
`register()` of the same id starts from it, so tokens never go backwards per id.

#### Parameters

| Parameter | Type |
| - | - |
| `id` | `string` |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`ScheduleStore`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore).[`delete`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore#delete)

***

### list()

```ts theme={null}
list(): Promise<ScheduleRecord[]>;
```

Defined in: [scheduler/ScheduleStore.ts:232](https://github.com/andresayac/botmesh/blob/main/packages/core/src/scheduler/ScheduleStore.ts#L232)

Every stored record (orphans included), in no particular order.

#### Returns

`Promise`\<[`ScheduleRecord`](https://botmesh.afaya.com.co/api/core/spi/interfaces/ScheduleRecord)\[]>

#### Implementation of

[`ScheduleStore`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore).[`list`](https://botmesh.afaya.com.co/api/core/interfaces/ScheduleStore#list)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.