Git Product home page Git Product logo

xk6-celery's Introduction

xk6-celery

A simple Celery tasks submitter/checker extension for k6. It relies on github.com/gocelery/gocelery library & use redis connection pooling at K6 object level.

Known current limitations

  • This extension is only meant to sumbit Celery tasks and (eventually) check task completion.
  • This extension does not validate task success, it only checks if the tasks has a result.
  • Redis is the only Celery backend currently supported.
  • Tasks using kwargs are not supported.

Also, we do not intend to support & bind all gocelery functions in this project.

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

  1. Build with xk6:
xk6 build --with github.com/ubbleai/xk6-celery

This will result in a k6 binary in the current directory.

  1. Run with the just build `k6:
./k6 run example.js

Functions

import celery from 'k6/x/celery';

// Create a new Celery Redis Client
// No worker are spawned. We are running in client-only mode.
const client = new celery.Redis({
  url: "redis://127.0.0.1:6379",
  queue: "taskqueue",
});

// Publish a new task with a three positional arguments
// Task id is returned as a string
const taskID = client.delay("my_task", "text-value", 101, ["any", "arg", "type", "allowed"]);

// Check if task have been completed (whether it's a success or not)
// boolean returned
const processed = client.taskCompleted(taskID);
if processed === True {
  console.log("Task processed");
} else {
  console.log("Task still pending");
}

// Wait for task completion using a blocking func call
// boolean returned (returns false if we hit timeout)
const deadlineCompleted = client.waitForTaskCompleted(taskID);
console.log(`Task completed within a timeframe = ${deadlineCompleted}`);

Javascript client configuration

JSON Key Default value Description
url "redis://127.0.0.1:6379" Celery Client endpoint URL (only Redis supported ATM)
queue "celery" Celery queue where to publish tasks
timeout "30s" Timeout used in waitForTaskCompleted function
getinterval "50ms" Check interval used in waitForTaskCompleted function

example :

const client = new celery.Redis({
  "url": "redis://my-redis:6379/0",
  "queue": "worker-queue-1",
  "timeout": "10s",
  "getinterval": "100ms",
});

Future

  • add check success functions
  • support AMQP
  • clean code/tests & add more opts

xk6-celery's People

Contributors

sebglon avatar barthv avatar

Watchers

0xch3221323 avatar  avatar  avatar  avatar Nicolas Debernardi avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.