Skip to content

Commit cbf9cda

Browse files
committed
Added a scheduler example
1 parent 0bc6f46 commit cbf9cda

File tree

8 files changed

+141
-0
lines changed

8 files changed

+141
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ docs/_build
4747
# Pytest
4848
coverage.xml
4949
junit.xml
50+
*celerybeat-schedule*
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.txt *.ini *.cfg *.rst
2+
recursive-include scheduler_example *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml

examples/scheduler_example/README.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Getting Started
2+
===============================
3+
Make sure you have a local redis-server running and then do:
4+
5+
.. code-block:: bash
6+
7+
$ pip install -e .
8+
$ celery worker -A pyramid_celery.celery_app --ini development.ini -B
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
###
2+
# app configuration
3+
# http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/environment.html
4+
###
5+
6+
[app:main]
7+
use = egg:scheduler_example
8+
9+
pyramid.reload_templates = true
10+
pyramid.debug_authorization = false
11+
pyramid.debug_notfound = false
12+
pyramid.debug_routematch = false
13+
pyramid.default_locale_name = en
14+
pyramid.includes =
15+
pyramid_debugtoolbar
16+
17+
# By default, the toolbar only appears for clients from IP addresses
18+
# '127.0.0.1' and '::1'.
19+
# debugtoolbar.hosts = 127.0.0.1 ::1
20+
21+
###
22+
# wsgi server configuration
23+
###
24+
25+
[celery]
26+
BROKER_URL = redis://localhost:6379/0
27+
28+
[celerybeat:task1]
29+
task = scheduler_example.tasks.get_date
30+
type = integer
31+
schedule = 10
32+
33+
[server:main]
34+
use = egg:waitress#main
35+
host = 0.0.0.0
36+
port = 6543
37+
38+
###
39+
# logging configuration
40+
# http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/logging.html
41+
###
42+
43+
[loggers]
44+
keys = root, scheduler_example
45+
46+
[handlers]
47+
keys = console
48+
49+
[formatters]
50+
keys = generic
51+
52+
[logger_root]
53+
level = INFO
54+
handlers = console
55+
56+
[logger_scheduler_example]
57+
level = DEBUG
58+
handlers =
59+
qualname = scheduler_example
60+
61+
[handler_console]
62+
class = StreamHandler
63+
args = (sys.stderr,)
64+
level = NOTSET
65+
formatter = generic
66+
67+
[formatter_generic]
68+
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pyramid.config import Configurator
2+
3+
4+
def main(global_config, **settings):
5+
""" This function returns a Pyramid WSGI application.
6+
"""
7+
settings['message'] = "The current date is %s"
8+
config = Configurator(settings=settings)
9+
config.scan()
10+
return config.make_wsgi_app()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pyramid_celery import celery_app as app
2+
from datetime import datetime
3+
import logging
4+
logger = logging.getLogger(__name__)
5+
6+
7+
@app.task
8+
def get_date(*args, **kwargs):
9+
msg = app.conf['PYRAMID_REGISTRY'].settings['message']
10+
11+
print(msg % datetime.utcnow())
12+
logger.info(msg % datetime.utcnow())

examples/scheduler_example/scheduler_example/views.py

Whitespace-only changes.

examples/scheduler_example/setup.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import os
2+
3+
from setuptools import setup, find_packages
4+
5+
here = os.path.abspath(os.path.dirname(__file__))
6+
7+
with open(os.path.join(here, 'README.rst')) as f:
8+
README = f.read()
9+
10+
requires = [
11+
'pyramid',
12+
'pyramid_celery',
13+
'redis',
14+
'watiress',
15+
]
16+
17+
setup(name='scheduler_example',
18+
version='0.0',
19+
description='scheduler_example',
20+
long_description=README,
21+
classifiers=[
22+
"Programming Language :: Python",
23+
"Framework :: Pyramid",
24+
"Topic :: Internet :: WWW/HTTP",
25+
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
26+
],
27+
author='',
28+
author_email='',
29+
url='',
30+
keywords='web pyramid pylons',
31+
packages=find_packages(),
32+
include_package_data=True,
33+
zip_safe=False,
34+
install_requires=requires,
35+
tests_require=requires,
36+
test_suite="scheduler_example",
37+
entry_points="""\
38+
[paste.app_factory]
39+
main = scheduler_example:main
40+
""",)

0 commit comments

Comments
 (0)