Coder Social home page Coder Social logo

carotte's Introduction

Carotte

Carotte is a very lightweight Celery on zmq.

Install

pip install carotte

Getting started

Create your app.py:

from carotte import Carotte

my_app = Carotte()

@my_app.task
def hello_world(name):
    return 'Hello %s!' % name

Run your worker (default on "tcp://127.0.0.1:5550"):

carotte worker --app app:my_app

Run tasks:

>>> from app import hello_world
>>> t = hello_world.delay(['Carotte'])
>>> t.success
>>> True
>>> t.result
>>> 'Hello Carotte!'

Or run a client (if don't have tasks on your system):

>>> from carotte import Client
>>> client = Client()
>>> task = client.run_task('hello_world', ['Carotte'])
>>> task.success
>>> True
>>> task.result
>>> 'Hello Carotte!'

Scheduled tasks

Carotte is not a scheduler, its an asynchronous tasks runner. But you can really set up scheduled tasks with schedule.

Your app.py:

import requests
from carotte import Carotte

my_app = Carotte()

@app.task
def get(url):
    r = requests.get(url)
    if r.status_code != 200:
        # Do stuff
        return False
    return True

Your scheduler.py:

import time
import schedule
from app import get

schedule.every(10).seconds.do(get, 'http://google.com')

while True:
    schedule.run_pending()
    time.sleep(1)

Run your worker and your scheduler:

carotte worker --app app:my_app
python scheduler.py

carotte's People

Contributors

toxinu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

carotte's Issues

module not found

when I try to

carotte worker --tasks-module tasks

carotte always said to me that import() doesn't fin my module. I tried with a real module (directory with init.py) and from several test with tasks.py alone.

I can import my module through the python interpreter and work with it, but carotte doesn't find it

No module named 'carotte.results'

(venv)[illusive@theShittyRacoon tmp]$ carotte --tasks-module task.py 
Traceback (most recent call last):
  File "/opt/git/carotte/venv/bin/carotte", line 5, in <module>
    pkg_resources.run_script('carotte==0.0.4', 'carotte')
  File "/opt/git/carotte/venv/lib/python3.4/site-packages/pkg_resources.py", line 488, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/opt/git/carotte/venv/lib/python3.4/site-packages/pkg_resources.py", line 1361, in run_script
    exec(script_code, namespace, namespace)
  File "/opt/git/carotte/venv/lib/python3.4/site-packages/carotte-0.0.4-py3.4.egg/EGG-INFO/scripts/carotte", line 4, in <module>
    import pkg_resources
  File "/opt/git/carotte/venv/lib/python3.4/site-packages/carotte-0.0.4-py3.4.egg/carotte/__init__.py", line 12, in <module>
  File "/opt/git/carotte/venv/lib/python3.4/site-packages/carotte-0.0.4-py3.4.egg/carotte/worker.py", line 15, in <module>
ImportError: No module named 'carotte.results'

j'ai python setup install, copié collé ton code de test dans un fichier task.py, je vais pour lancer le worker et boom

je suis dans un venv, python 3.4, archlinux

missing in docs - how to run task on different workers ? how to use broker?

Just after few minutes of playing with carotte i must say i like it.

But docs should really have examples for those use cases:

When i am running carrotte on different addresses like this:
carotte worker --app app:my_app --bind=inproc://tmp/aa
how should i call my tasks?

How to run tasks on different workers with and without broker? How to run broker?

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.