{"id":19253449,"url":"https://github.com/stevearc/eat_your_vegetables","last_synced_at":"2025-02-23T17:12:57.461Z","repository":{"id":15908546,"uuid":"18650153","full_name":"stevearc/eat_your_vegetables","owner":"stevearc","description":"An organizational wrapper around celery","archived":false,"fork":false,"pushed_at":"2015-06-04T15:39:43.000Z","size":160,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T08:51:59.302Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevearc.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-10T20:08:57.000Z","updated_at":"2017-03-23T14:39:41.000Z","dependencies_parsed_at":"2022-09-24T05:41:03.775Z","dependency_job_id":null,"html_url":"https://github.com/stevearc/eat_your_vegetables","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevearc%2Feat_your_vegetables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevearc%2Feat_your_vegetables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevearc%2Feat_your_vegetables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevearc%2Feat_your_vegetables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevearc","download_url":"https://codeload.github.com/stevearc/eat_your_vegetables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240347981,"owners_count":19787237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T18:31:05.639Z","updated_at":"2025-02-23T17:12:57.435Z","avatar_url":"https://github.com/stevearc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Eat Your Vegetables\n===================\nThis is a wrapper framework that makes it easier to organize your celery tasks.\nThe include system is heavily influenced by `Pyramid\n\u003chttp://www.pylonsproject.org/\u003e`_.\n\nAdding Tasks\n============\nInside your package, create a ``tasks.py`` file (the name isn't important) with\nthe following::\n\n    from eat_your_vegetables import celery, BaseTask\n\n    @celery.task(base=BaseTask)\n    def say_hello(name):\n        return \"Hello %s!\" % name\n\nThen add ``yourextension.tasks`` to the ``CELERY_IMPORTS`` section of the\nconfig.yaml file (see the Configuration section below)\n\nExtensions\n==========\nEat Your Vegetables can load extensions.  It imports every module in the\n``include`` list and runs the ``include_tasks`` function from that module. The\nfunction should accept a ``eat_your_vegetables.TaskConfigurator`` as the only\nargument.\n\nYou can use this to add mixins (providing more methods to the tasks), schedule\nperiodic tasks, or mutate the celery configuration. For example, to schedule a\nperiodic callback::\n\n    def include_tasks(config):\n        config.add_scheduled_task('constant_greeting', {\n            'task': 'yourextension.tasks.say_hello',\n            'schedule': timedelta(minutes=1),\n            'args': ['Monty'],\n        })\n\nYou can also add mixins during the configure step. Mixins will provide\nadditional methods to the tasks. Here is a mixin that provides a method to\nrender jinja2 templates. Note that you would have to set\n``config.registry.jinja2_env`` in the ``include_tasks`` function::\n\n    class JinjaRenderMixin(object):\n\n        def render(self, template, **kwargs):\n            \"\"\" Render a jinja2 template \"\"\"\n            env = self.config.registry.jinja2_env\n            tmpl = env.get_template(template)\n            return tmpl.render(**kwargs)\n\nAnd another mixin that provides a SQLAlchemy session::\n\n    from sqlalchemy import engine_from_config\n\n    class DatabaseTaskMixin(object):\n        _sessionmaker = None\n        _db = None\n\n        @property\n        def db(self):\n            # Lazily create the sessionmaker and the session\n            if self._sessionmaker is None:\n                engine = engine_from_config(self.config.settings,\n                                            prefix='sqlalchemy.')\n                self._sessionmaker = sessionmaker(bind=engine)\n            if self._db is None:\n                self._db = self._sessionmaker()\n\n                def cleanup(task, status, retval, task_id, args, kwargs, einfo):\n                    if einfo is None:\n                        task.db.commit()\n                    else:\n                        task.db.rollback()\n                self.callbacks.append(cleanup)\n            return self._db\n\nConfiguration\n=============\n::\n\n    # Dict for configuring logging (required; see logging.dictConfig)\n    logging:\n      version: 1\n      formatters:\n        simple:\n          format: '%(levelname)s %(asctime)s [%(name)s] %(message)s'\n      root:\n        handlers:\n          - console\n        level: INFO\n      loggers:\n        eat_your_vegetables:\n          handlers:\n            - console\n          level: INFO\n          propagate: false\n      handlers:\n        console\n          class: StreamHandler\n          formatter: simple\n\n    # Dict with the celery configuration (required)\n    celery:\n      CELERY_TASK_SERIALIZER: json\n      CELERY_ACCEPT_CONTENT:\n        - json\n      CELERY_RESULT_SERIALIZER: json\n      CELERY_RESULT_BACKEND: database\n      CELERY_RESULT_DBURI: sqlite:///{here}/celery_results.sqlite\n      BROKER_URL: sqla+sqlite:///{here}/celery_broker.sqlite\n      CELERY_IMPORTS: []\n\n    # Dotted path to a lock factory implementation. (See eat_your_vegetables.locks)\n    lock_factory = none\n\n    # Modules that include an 'include_tasks' function\n    include:\n      - mypackage.tasks\n      - mypackage2.tasks\n\nRunning\n=======\nEat Your Vegetables provides CLI commands that wrap celery. Just specify the\nconfig file as the first argument, and the rest of the arguments will be passed\non to the celery commands as per usual. There are three commands:\n\n* **nom-worker** - Starts a celery worker\n* **nom-beat** - Starts celerybeat \n* **nom-flower** - Starts celery flower (you must ``pip install flower`` first)\n\nFrom your webserver or anywhere else, call\n``eat_your_vegetables.init_celery(yaml_file, configure_log=False)``. You will\nneed to do this before you import any modules with tasks in them.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevearc%2Feat_your_vegetables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevearc%2Feat_your_vegetables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevearc%2Feat_your_vegetables/lists"}