Skip to content

theboringhumane/cleo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

37 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cleo ๐Ÿš€

Cleo Logo

Why did the task queue go to therapy? It had too many unresolved promises! ๐Ÿ˜…

A distributed task queue system that's seriously powerful (but doesn't take itself too seriously ๐ŸŽญ).

Cleo Logo

Docs

Features โœจ

  • Task Grouping ๐ŸŽฏ - Because some tasks are more social than others
  • Distributed Locking ๐Ÿ” - No queue jumping allowed!
  • Retry with Backoff ๐Ÿ”„ - If at first you don't succeed... we got you covered
  • Redis-Backed ๐Ÿ“ฆ - Because memory is fleeting, but Redis is forever
  • TypeScript Support ๐Ÿ’ช - For when any just won't cut it

Core Superpowers ๐Ÿ’ซ

Task Processing ๐ŸŽฏ

  • ๐Ÿš€ Distributed processing with auto load balancing
  • ๐ŸŽญ Group task management (for tasks that play well with others)
  • ๐Ÿ“Š Real-time monitoring (because we're all a bit nosy)
  • โญ Priority-based processing (some tasks are just more important)
  • โšก Event-driven architecture (Redis pub/sub magic)
  • ๐Ÿ›ก๏ธ Built-in error handling (because stuff happens)
  • ๐Ÿ“ˆ Performance metrics (for the data nerds)

Group Processing Strategies ๐ŸŽฒ

  • ๐Ÿ”„ Round Robin: Fair play for all tasks
  • ๐Ÿ“ FIFO: First in, first out (no cutting in line!)
  • โญ Priority: VIP tasks get VIP treatment
  • ๐ŸŽฏ Dynamic: Adapts faster than a developer during a production incident

Advanced Features ๐Ÿ”ฌ

  • ๐ŸŽฏ Smart Batching

    • Groups tasks like a pro party planner
    • Optimizes performance like a caffeine-powered compiler
    • Handles bursts better than your morning coffee machine
  • ๐Ÿ“Š Real-time Analytics

    • Success/failure tracking (keeping score)
    • Processing time stats (for the speed demons)
    • Resource usage metrics (watching the diet)
    • Performance insights (big brain time)

Security & Protection ๐Ÿ›ก๏ธ

  • ๐Ÿ” Redis ACL support (because sharing isn't always caring)
  • ๐ŸŽฏ Task-level permissions (not everyone gets a backstage pass)
  • ๐Ÿ“ Audit logging (tracking who did what)
  • ๐Ÿ”‘ Role-based access (VIP list management)

System Architecture ๐Ÿ—๏ธ

(Where all the magic happens โœจ)

graph TB
    Client[๐Ÿ–ฅ๏ธ Client] --> QM[๐Ÿ“Š Queue Manager]
    QM --> Redis[(๐Ÿ’พ Redis)]
    QM --> Worker[๐Ÿ‘ท Worker Pool]
    QM --> Groups[๐Ÿ‘ฅ Task Groups]
    Worker --> Redis
    Groups --> Redis
    
    subgraph "๐ŸŽญ Task Party"
        Groups --> Strategy{๐ŸŽฏ Strategy}
        Strategy --> RR[๐Ÿ”„ Round Robin]
        Strategy --> FIFO[๐Ÿ“ FIFO]
        Strategy --> Priority[โญ Priority]
    end

    subgraph "๐Ÿ’ช Worker Squad"
        Worker --> W1[๐Ÿƒ Worker 1]
        Worker --> W2[๐Ÿƒโ€โ™€๏ธ Worker 2]
        Worker --> W3[๐Ÿƒโ€โ™‚๏ธ Worker 3]
    end
Loading

Task Flow ๐ŸŒŠ

(AKA: The Epic Journey of a Task)

sequenceDiagram
    participant C as ๐Ÿ–ฅ๏ธ Client
    participant QM as ๐Ÿ“Š Queue
    participant G as ๐Ÿ‘ฅ Group
    participant W as ๐Ÿ‘ท Worker
    participant R as ๐Ÿ’พ Redis

    C->>QM: Submit Task ๐Ÿ“ฌ
    QM->>G: Group Check ๐Ÿ”
    G->>R: Store State ๐Ÿ’พ
    QM->>R: Queue Task โžก๏ธ
    W->>R: Poll Tasks ๐ŸŽฃ
    W->>G: Check Order ๐Ÿ“‹
    W->>QM: Process โš™๏ธ
    QM->>C: Done! ๐ŸŽ‰
Loading

Real-World Examples ๐ŸŒ

(Because who doesn't love practical examples?)

Video Processing ๐ŸŽฅ

graph TB
    Upload[๐Ÿ“ค Upload] --> Process[โš™๏ธ Process]
    Process --> Encode[๐ŸŽฌ Encode]
    Encode --> Deliver[๐Ÿš€ Deliver]
    
    style Upload fill:#f9f,stroke:#333
    style Process fill:#bbf,stroke:#333
    style Encode fill:#bfb,stroke:#333
    style Deliver fill:#fbf,stroke:#333
Loading

Installation ๐Ÿ› ๏ธ

npm install @cleo/core
# or if you're yarn-core'd
yarn add @cleo/core

Quick Start ๐Ÿƒโ€โ™‚๏ธ

Examples ๐ŸŽฎ

(Because the best way to learn is by doing!)

Quick Start ๐Ÿš€

import { Cleo } from '@cleo/core';

// Get your Cleo instance (it's like a task-managing pet)
const cleo = Cleo.getInstance();

// Configure it (give it treats and training)
cleo.configure({
  redis: {
    host: "localhost",
    port: 6379,
    password: "cleosecret",
  },
  worker: {
    concurrency: 4,
    queues: [
      {
        name: "send-email",
        priority: TaskPriority.HIGH,
      },
    ],
  },
});

// Monitor your tasks (helicopter parenting, but for code)
const queueManager = cleo.getQueueManager();
queueManager.onTaskEvent(ObserverEvent.STATUS_CHANGE, (taskId, status, data) => {
  console.log(`Task ${taskId} status changed to ${status}`, data);
});

Task Decorators ๐ŸŽ€

import { task } from "@cleo/core";

class EmailService {
  @task({
    id: "send-email",
    priority: TaskPriority.HIGH,
    queue: 'send-email',
  })
  async sendEmail(input: { email: string }): Promise<string> {
    // Your email sending logic here
    return `Sent to ${input.email}`;
  }
}

Advanced Group Processing ๐ŸŽญ

import { QueueClass, GroupProcessingStrategy } from "@cleo/core";

// Define a service with group settings
@QueueClass({
  defaultOptions: {
    maxRetries: 3,
    retryDelay: 1000,
    backoff: {
      type: "fixed",
      delay: 2000,
    },
    group: "notifications",
    timeout: 300000,
  },
  queue: "notifications",
})
class NotificationService {
  async sendPushNotification(data: { message: string }) {
    console.log(`๐Ÿ“ฑ Sending push: ${data.message}`);
    return `Notification sent: ${data.message}`;
  }

  async sendSMS(data: { message: string }) {
    console.log(`๐Ÿ“ฒ Sending SMS: ${data.message}`);
    return `SMS sent: ${data.message}`;
  }
}

// Use different processing strategies
const queueManager = cleo.getQueueManager();

// Round Robin (taking turns like a proper queue)
queueManager.setGroupProcessingStrategy(GroupProcessingStrategy.ROUND_ROBIN);

// FIFO (first in, first out, just like a coffee shop)
queueManager.setGroupProcessingStrategy(GroupProcessingStrategy.FIFO);

// Priority (VIP treatment for important tasks)
queueManager.setGroupProcessingStrategy(GroupProcessingStrategy.PRIORITY);
await queueManager.setGroupPriority("notifications", 10);

Error Handling & Retries ๐Ÿ›Ÿ

// Built-in retry configuration
@QueueClass({
  defaultOptions: {
    maxRetries: 3,
    backoff: {
      type: "fixed",
      delay: 2000,
    },
    retryDelay: 1000,
  }
})
class ReliableService {
  async mightFail() {
    // Will retry 3 times with backoff
    throw new Error("Oops!");
  }
}

// Manual retry with backoff
import { RetryWithBackoff } from "@cleo/core";

const result = await retryWithBackoff(
  async () => {
    return await unreliableOperation();
  },
  3,    // max retries
  1000  // base delay in ms
);

Event Monitoring ๐Ÿ“Š

const queueManager = cleo.getQueueManager();

// Monitor all the things!
queueManager.onTaskEvent(ObserverEvent.STATUS_CHANGE, (taskId, status, data) => {
  console.log(`๐Ÿ’ฌ Task ${taskId} status: ${status}`);
});

queueManager.onTaskEvent(ObserverEvent.GROUP_CHANGE, (taskId, status, data) => {
  console.log(`๐Ÿ‘ฅ Group operation: ${data.operation}`);
});

queueManager.onTaskEvent(ObserverEvent.TASK_COMPLETED, (taskId, status, result) => {
  console.log(`โœ… Task ${taskId} completed:`, result);
});

queueManager.onTaskEvent(ObserverEvent.TASK_FAILED, (taskId, status, error) => {
  console.log(`โŒ Task ${taskId} failed:`, error);
});

Complete Examples ๐Ÿ“š

Check out our example files for full implementations:

Each example comes with:

  • ๐ŸŽฏ Complete setup and configuration
  • ๐Ÿ“Š Event monitoring setup
  • ๐ŸŽญ Different processing strategies
  • ๐Ÿ› ๏ธ Error handling patterns
  • ๐Ÿ“ˆ Performance monitoring

Contributing ๐Ÿค

We welcome contributions! Whether you're fixing bugs ๐Ÿ›, adding features โœจ, or improving docs ๐Ÿ“š, we'd love your help!

Q: How many developers does it take to review a PR? A: None, they're all stuck in an infinite loop of bikeshedding! ๐Ÿ˜„

Check out our Contributing Guidelines for:

  • Code style and standards ๐Ÿ“
  • Development workflow ๐Ÿ”„
  • Project structure ๐Ÿ—๏ธ
  • Pull request process ๐Ÿ”
  • Bug reporting guidelines ๐Ÿž

Key Components ๐Ÿ”ง

Our project is like a well-oiled machine (that occasionally needs coffee):

  • QueueManager ๐Ÿ“Š - The traffic controller of your tasks
  • TaskGroup ๐Ÿ‘ฅ - Because tasks work better in teams
  • Worker ๐Ÿƒ - The real MVP doing all the heavy lifting
  • Utilities ๐Ÿ› ๏ธ - Our Swiss Army knife of helper functions

Performance Features โšก

(Because speed matters!)

graph LR
    A[๐Ÿ“Š Smart Batching] --> B[โšก Fast Processing]
    B --> C[๐ŸŽฏ Optimal Results]
    C --> D[๐ŸŽ‰ Happy Users]
    
    style A fill:#f96,stroke:#333
    style B fill:#9cf,stroke:#333
    style C fill:#9f9,stroke:#333
    style D fill:#f9f,stroke:#333
Loading

License ๐Ÿ“œ

MIT License - see LICENSE file for details

Remember: In a world of callbacks, promises, and async/await, we're all just trying our best to avoid race conditions! ๐Ÿ


Made with โค๏ธ and probably too much caffeine โ˜•

About

A distributed task queue system that's seriously powerful (but doesn't take itself too seriously ๐ŸŽญ).

Resources

Stars

Watchers

Forks

Packages

No packages published