143 lines
2.8 KiB
Markdown
143 lines
2.8 KiB
Markdown
# Osiris Runner
|
|
|
|
Database-backed runner for structured data storage and retrieval.
|
|
|
|
## Overview
|
|
|
|
The Osiris runner executes Rhai scripts with access to a model-based database system, enabling structured data operations and persistence.
|
|
|
|
## Features
|
|
|
|
- **Rhai Scripting**: Execute Rhai scripts with Osiris database access
|
|
- **Model-Based Storage**: Define and use data models
|
|
- **CRUD Operations**: Create, read, update, delete records
|
|
- **Query Support**: Search and filter data
|
|
- **Schema Validation**: Type-safe data operations
|
|
- **Transaction Support**: Atomic database operations
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
# Start the runner
|
|
runner_osiris my-osiris-runner
|
|
|
|
# With custom Redis
|
|
runner_osiris my-osiris-runner --redis-url redis://custom:6379
|
|
```
|
|
|
|
## Job Payload
|
|
|
|
The payload should contain a Rhai script using Osiris operations:
|
|
|
|
```rhai
|
|
// Example: Store data
|
|
let model = osiris.model("users");
|
|
let user = model.create(#{
|
|
name: "Alice",
|
|
email: "alice@example.com",
|
|
age: 30
|
|
});
|
|
print(user.id);
|
|
|
|
// Example: Retrieve data
|
|
let found = model.get(user.id);
|
|
print(found.name);
|
|
```
|
|
|
|
## Examples
|
|
|
|
### Create Model and Store Data
|
|
```rhai
|
|
// Define model
|
|
let posts = osiris.model("posts");
|
|
|
|
// Create record
|
|
let post = posts.create(#{
|
|
title: "Hello World",
|
|
content: "First post",
|
|
author: "Alice",
|
|
published: true
|
|
});
|
|
|
|
print(`Created post with ID: ${post.id}`);
|
|
```
|
|
|
|
### Query Data
|
|
```rhai
|
|
let posts = osiris.model("posts");
|
|
|
|
// Find by field
|
|
let published = posts.find(#{
|
|
published: true
|
|
});
|
|
|
|
for post in published {
|
|
print(post.title);
|
|
}
|
|
```
|
|
|
|
### Update Records
|
|
```rhai
|
|
let posts = osiris.model("posts");
|
|
|
|
// Get record
|
|
let post = posts.get("post-123");
|
|
|
|
// Update fields
|
|
post.content = "Updated content";
|
|
posts.update(post);
|
|
```
|
|
|
|
### Delete Records
|
|
```rhai
|
|
let posts = osiris.model("posts");
|
|
|
|
// Delete by ID
|
|
posts.delete("post-123");
|
|
```
|
|
|
|
### Transactions
|
|
```rhai
|
|
osiris.transaction(|| {
|
|
let users = osiris.model("users");
|
|
let posts = osiris.model("posts");
|
|
|
|
let user = users.create(#{ name: "Bob" });
|
|
let post = posts.create(#{
|
|
title: "Bob's Post",
|
|
author_id: user.id
|
|
});
|
|
|
|
// Both operations commit together
|
|
});
|
|
```
|
|
|
|
## Data Models
|
|
|
|
Models are defined dynamically through Rhai scripts:
|
|
|
|
```rhai
|
|
let model = osiris.model("products");
|
|
|
|
// Model automatically handles:
|
|
// - ID generation
|
|
// - Timestamps (created_at, updated_at)
|
|
// - Schema validation
|
|
// - Indexing
|
|
```
|
|
|
|
## Requirements
|
|
|
|
- Redis server accessible
|
|
- Osiris database configured
|
|
- Valid job signatures
|
|
- Sufficient storage for data operations
|
|
|
|
## Use Cases
|
|
|
|
- **Configuration Storage**: Store application configs
|
|
- **User Data**: Manage user profiles and preferences
|
|
- **Workflow State**: Persist workflow execution state
|
|
- **Metrics & Logs**: Store structured logs and metrics
|
|
- **Cache Management**: Persistent caching layer
|