Navigation Menu

Skip to content

Commit

Permalink
Added a scheduler example
Browse files Browse the repository at this point in the history
  • Loading branch information
sontek committed Dec 28, 2014
1 parent 0bc6f46 commit cbf9cda
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -47,3 +47,4 @@ docs/_build
# Pytest
coverage.xml
junit.xml
*celerybeat-schedule*
2 changes: 2 additions & 0 deletions examples/scheduler_example/MANIFEST.in
@@ -0,0 +1,2 @@
include *.txt *.ini *.cfg *.rst
recursive-include scheduler_example *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml
8 changes: 8 additions & 0 deletions examples/scheduler_example/README.rst
@@ -0,0 +1,8 @@
Getting Started
===============================
Make sure you have a local redis-server running and then do:

.. code-block:: bash
$ pip install -e .
$ celery worker -A pyramid_celery.celery_app --ini development.ini -B
68 changes: 68 additions & 0 deletions examples/scheduler_example/development.ini
@@ -0,0 +1,68 @@
###
# app configuration
# http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/environment.html
###

[app:main]
use = egg:scheduler_example

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar

# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
# debugtoolbar.hosts = 127.0.0.1 ::1

###
# wsgi server configuration
###

[celery]
BROKER_URL = redis://localhost:6379/0

[celerybeat:task1]
task = scheduler_example.tasks.get_date
type = integer
schedule = 10

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543

###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/logging.html
###

[loggers]
keys = root, scheduler_example

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_scheduler_example]
level = DEBUG
handlers =
qualname = scheduler_example

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
10 changes: 10 additions & 0 deletions examples/scheduler_example/scheduler_example/__init__.py
@@ -0,0 +1,10 @@
from pyramid.config import Configurator


def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings['message'] = "The current date is %s"
config = Configurator(settings=settings)
config.scan()
return config.make_wsgi_app()
12 changes: 12 additions & 0 deletions examples/scheduler_example/scheduler_example/tasks.py
@@ -0,0 +1,12 @@
from pyramid_celery import celery_app as app
from datetime import datetime
import logging
logger = logging.getLogger(__name__)


@app.task
def get_date(*args, **kwargs):
msg = app.conf['PYRAMID_REGISTRY'].settings['message']

print(msg % datetime.utcnow())
logger.info(msg % datetime.utcnow())
Empty file.
40 changes: 40 additions & 0 deletions examples/scheduler_example/setup.py
@@ -0,0 +1,40 @@
import os

from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(here, 'README.rst')) as f:
README = f.read()

requires = [
'pyramid',
'pyramid_celery',
'redis',
'watiress',
]

setup(name='scheduler_example',
version='0.0',
description='scheduler_example',
long_description=README,
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
author='',
author_email='',
url='',
keywords='web pyramid pylons',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=requires,
tests_require=requires,
test_suite="scheduler_example",
entry_points="""\
[paste.app_factory]
main = scheduler_example:main
""",)

0 comments on commit cbf9cda

Please sign in to comment.