Skip to content

Commit

Permalink
Move scripts into their own isolated package.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpm committed Oct 19, 2018
1 parent 99448a8 commit 2e6f463
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 54 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
recursive-include dallinger *
recursive-include dallinger_scripts *
recursive-include docs *

include requirements.txt
Expand Down
4 changes: 0 additions & 4 deletions dallinger/heroku/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,3 @@ def launch():
if not config.ready:
config.load()
scheduler.start()


if __name__ == '__main__':
launch()
55 changes: 9 additions & 46 deletions dallinger/heroku/worker.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,9 @@
"""Heroku web worker."""
# Make sure gevent patches are applied early.
import os

listen = ['high', 'default', 'low']


def main():
import gevent.monkey
gevent.monkey.patch_all()

# These imports are inside the __main__ block
# to make sure that we only import from rq_gevent_worker
# (which has the side effect of applying gevent monkey patches)
# in the worker process. This way other processes can import the
# redis connection without that side effect.
from rq import (
Queue,
Connection
)
from dallinger.db import redis_conn
from dallinger.heroku.rq_gevent_worker import GeventWorker as Worker

from dallinger.config import initialize_experiment_package
initialize_experiment_package(os.getcwd())

import logging
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)

with Connection(redis_conn):
worker = Worker(list(map(Queue, listen)))
worker.work()


if __name__ == '__main__': # pragma: nocover
main()
else:
import warnings
warnings.warn(
u"Importing from heroku.worker is deprecated and may cause errors."
u"The redis `conn` should be imported from `dallinger.db.redis_conn`",
DeprecationWarning
)
from dallinger.db import redis_conn

conn = redis_conn
import warnings
from dallinger.db import redis_conn
warnings.warn(
u"Importing from heroku.worker is deprecated and may cause errors."
u"The redis `conn` should be imported from `dallinger.db.redis_conn`",
DeprecationWarning
)

conn = redis_conn
Empty file added dallinger_scripts/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions dallinger_scripts/clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def main():
from dallinger.heroku.clock import launch
launch()


if __name__ == '__main__':
main()
File renamed without changes.
36 changes: 36 additions & 0 deletions dallinger_scripts/worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Heroku web worker."""
# Make sure gevent patches are applied early.
import os

listen = ['high', 'default', 'low']


def main():
import gevent.monkey
gevent.monkey.patch_all()

# These imports are inside the __main__ block
# to make sure that we only import from rq_gevent_worker
# (which has the side effect of applying gevent monkey patches)
# in the worker process. This way other processes can import the
# redis connection without that side effect.
from rq import (
Queue,
Connection
)
from dallinger.db import redis_conn
from dallinger.heroku.rq_gevent_worker import GeventWorker as Worker

from dallinger.config import initialize_experiment_package
initialize_experiment_package(os.getcwd())

import logging
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)

with Connection(redis_conn):
worker = Worker(list(map(Queue, listen)))
worker.work()


if __name__ == '__main__': # pragma: nocover
main()
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup_args = dict(
name='dallinger',
packages=['dallinger'],
packages=['dallinger', 'dallinger_scripts'],
version="4.0.0",
description='Laboratory automation for the behavioral and social sciences',
url='http://github.com/Dallinger/Dallinger',
Expand All @@ -27,9 +27,9 @@
entry_points={
'console_scripts': [
'dallinger = dallinger.command_line:dallinger',
'dallinger_heroku_web = dallinger.heroku.launch:main',
'dallinger_heroku_worker = dallinger.heroku.worker:main',
'dallinger_heroku_clock = dallinger.heroku.clock:launch',
'dallinger_heroku_web = dallinger_scripts.web:main',
'dallinger_heroku_worker = dallinger_scripts.worker:main',
'dallinger_heroku_clock = dallinger_scripts.clock:main',
],
'dallinger.experiments': [],
},
Expand Down

0 comments on commit 2e6f463

Please sign in to comment.