Skip to content

Commit 3af175b

Browse files
committed
Request logic settings and improvements. Preparing to merge back to master
1 parent def8b82 commit 3af175b

File tree

6 files changed

+62
-51
lines changed

6 files changed

+62
-51
lines changed

app/django-bbx/bbx/settings.example.py

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
# Example: "/var/www/example.com/media/"
1515
MEDIA_ROOT = "/data/bbx/"
1616

17+
## Broker settings.
18+
BROKER_URL = 'amqp://guest:guest@localhost:5672//'
19+
20+
# List of modules to import when celery starts.
21+
CELERY_IMPORTS = ('repository.tasks',)
22+
23+
## Using the database to store task state and results.
24+
CELERY_RESULT_BACKEND = 'amqp'
25+
CELERY_TASK_RESULT_EXPIRES = 18000 # 5 hours.
26+
1727
# Change this to the full path to your own repository
1828
REPOSITORY_DIR_NAME ="repositories"
1929
REPOSITORY_DIR = os.path.join(MEDIA_ROOT, REPOSITORY_DIR_NAME)

app/django-bbx/mocambola/models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def mocambola_post_save(instance, **kwargs):
103103
fout.close()
104104
git_add(mocamboladata, mocambolapath)
105105
git_commit(mocamboladata, instance.user.get_username(),
106-
instance.user.email, instance.repository.get_path())
106+
instance.user.email, instance.repository.get_path(),
107+
os.path.join(mocambolapath, mocamboladata))
107108

108109
# TODO HIGH: Precisa serializar o user tambem na criaçao e update
109110
# diretamente pelo usuario

app/django-bbx/repository/models.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def git_media_post_save(instance, **kwargs):
4040
fout.close()
4141
git_add(mediadata, mediapath)
4242
git_commit(instance.get_file_name(),
43-
instance.author.username,
44-
instance.author.email,
45-
get_file_path(instance))
46-
43+
instance.author.username,
44+
instance.author.email,
45+
get_file_path(instance),
46+
os.path.join(mediapath, mediadata))
4747

4848

4949
def get_default_repository():
@@ -141,12 +141,12 @@ def git_rm(file_name, repository_path):
141141
pipe = subprocess.Popen(cmd, shell=True, cwd=repository_path)
142142
pipe.wait()
143143

144-
def git_commit(file_title, author_name, author_email, repository_path):
144+
def git_commit(file_title, author_name, author_email, repository_path, file_path):
145145
u"""Executa o *commit* no repositório impostando os dados do author."""
146146
logger.info('git commit --author="' + author_name + ' <' + author_email +
147147
'>" -m "' + file_title + '"')
148148
cmd = ('git commit --author="' + author_name + ' <' + author_email +
149-
'>" -m "' + file_title + '"')
149+
'>" -m "' + file_title + '" -- ' + file_path)
150150
pipe = subprocess.Popen(cmd, shell=True, cwd=repository_path)
151151
pipe.wait()
152152

@@ -220,11 +220,8 @@ def git_annex_copy_to(repository_path):
220220
def git_annex_where_is(media):
221221
u"""Mostra quais mucuas tem copia do media."""
222222
cmd = 'git annex whereis ' + media.get_file_name() + ' --json'
223-
logger.debug('Whereis filepath: ' + get_file_path(media) + media.get_file_name())
224223
pipe = subprocess.Popen(cmd, shell=True, cwd=get_file_path(media), stdout=subprocess.PIPE)
225224
output, error = pipe.communicate()
226-
logger.debug(error)
227-
logger.info(output)
228225
return output
229226

230227
def git_annex_drop(media):

bin/process-requests.sh.example

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
#
3+
# Para rodar esse script a cada minuto digitar
4+
# crontab -e
5+
# e colocar a linha:
6+
# */1 * * * * * /srv/bbx/bin/process-requests.sh
7+
8+
. /srv/bbx/envs/bbx/bin/activate
9+
python /srv/bbx/baobaxia/app/django-bbx/manage.py process_requests mocambos `hostname`
10+

conf/supervisor/celeryd

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[program:celery]
2+
; Set full path to celery program if using virtualenv
3+
command=/srv/bbx/envs/bbx/bin/celery worker -A bbx --loglevel=INFO
4+
directory=/srv/bbx/baobaxia/app/django-bbx
5+
user=exu
6+
numprocs=1
7+
stdout_logfile=/srv/bbx/log/celery/worker.log
8+
stderr_logfile=/srv/bbx/log/celery/worker_error.log
9+
autostart=true
10+
autorestart=true
11+
startsecs=10
12+
13+
environment =
14+
DJANGO_SETTINGS_MODULE=bbx.settings
15+
16+
; PYTHONPATH="/srv/bbx/envs/bbx/",

install.sh

+18-41
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ create_user() {
3131
# PRE: pkgs:
3232

3333
# dependencies: se for deb pkg, tirar
34-
<<<<<<< HEAD
35-
apt-get install git git-annex nginx supervisor python-pip rabbitmq-server
36-
=======
37-
apt-get install git git-annex nginx supervisor python-pip libjpeg-dev libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk python-dev python-setuptools
34+
apt-get install git git-annex nginx supervisor python-pip rabbitmq-server libjpeg-dev libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk python-dev python-setuptools
3835

3936

40-
>>>>>>> master
41-
4237
### cria diretorio basico
4338
mkdir -p $DEFAULT_REPOSITORY_DIR
4439

@@ -251,19 +246,7 @@ su - $USER_BBX -c "
251246
virtualenv $INSTALL_DIR/envs/bbx ;
252247
. $INSTALL_DIR/envs/bbx/bin/activate ;
253248
pip install --upgrade setuptools ;
254-
<<<<<<< HEAD
255249
cd $INSTALL_DIR;
256-
tar xjvf pip_wheel_20140606.tbz ;
257-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/argparse-1.2.1-py2-none-any.whl;
258-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/Django-1.6.5-py2.py3-none-any.whl;
259-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/django_extensions-1.1.1-py2-none-any.whl;
260-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/djangorestframework-2.3.6-py2-none-any.whl;
261-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/gunicorn-18.0-py2-none-any.whl;
262-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/six-1.3.0-py2-none-any.whl;
263-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/sorl_thumbnail-11.12.1b-py27-none-any.whl;
264-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/South-0.8.4-py2.py3-none-any.whl;
265-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/wheel-0.23.0-py2.py3-none-any.whl;
266-
# pip install --use-wheel --no-index --find-links=local/wheel local/wheel/wsgiref-0.1.2-py2-none-any.whl;
267250
pip install argparse;
268251
pip install django==1.6.7;
269252
pip install django-extensions;
@@ -274,21 +257,8 @@ pip install sorl-thumbnail;
274257
pip install south;
275258
pip install wheel;
276259
pip install wsgiref;
277-
pip install longerusername
278-
=======
279-
pip install Django==1.6.6 ;
280-
pip install Pillow==2.6.1 ;
281-
pip install South==1.0 ;
282-
pip install argparse==1.2.1 ;
283-
pip install django-extensions==1.3.11 ;
284-
pip install djangorestframework==2.3.14 ;
285-
pip install gunicorn==19.1.1 ;
286-
pip install longerusername==0.4 ;
287-
pip install six==1.7.3 ;
288-
pip install sorl-thumbnail==11.12 ;
289-
pip install wheel==0.24.0 ;
290-
pip install wsgiref==0.1.2 ;
291-
>>>>>>> master
260+
pip install longerusername;
261+
pip install celery
292262
"
293263

294264
echo ""
@@ -349,22 +319,29 @@ echo "Ativando NGINX ..."
349319
service nginx restart
350320

351321
echo ""
352-
echo "Criando arquivo de configuração do Supervisor ..."
322+
echo "Criando arquivo de configuração do Supervisor para BBX..."
353323
cp $INSTALL_DIR/baobaxia/conf/supervisor/bbx /etc/supervisor/conf.d/bbx.conf
354324
sed -i "s:_domain_:${BBX_DIR_NAME}:g" /etc/supervisor/conf.d/bbx.conf
355325

326+
echo ""
327+
echo "Criando arquivo de configuração do Supervisor para Celery..."
328+
cp $INSTALL_DIR/baobaxia/conf/supervisor/celeryd /etc/supervisor/conf.d/celeryd.conf
329+
356330
echo ""
357331
echo "Ativando o Baobáxia ..."
358332
supervisorctl reload
359333
supervisorctl restart bbx
334+
supervisorctl restart celeryd
360335

361-
#echo ""
362-
#echo "Ativando a sincronização (bbx-cron) ..."
363-
#cp $INSTALL_DIR/baobaxia/bin/bbx-cron.sh.example $INSTALL_DIR/bin/bbx-cron.sh
364-
#chmod +x $INSTALL_DIR/bin/bbx-cron.sh
365-
#touch /etc/cron.d/bbx
366-
#printf "# Sincronização do Baobáxia \n" >> /etc/cron.d/bbx
367-
#printf "*/30 * * * * * exu bash /srv/bbx/bin/bbx-cron.sh \n" >> /etc/cron.d/bbx
336+
echo ""
337+
echo "Instalando script de sincronização (bbx-cron) ..."
338+
cp $INSTALL_DIR/baobaxia/bin/bbx-cron.sh.example $INSTALL_DIR/bin/bbx-cron.sh
339+
chmod +x $INSTALL_DIR/bin/bbx-cron.sh
340+
341+
echo ""
342+
echo "Instalando script para pedidos de arquivos (process-requests) ..."
343+
cp $INSTALL_DIR/baobaxia/bin/process-requests.sh.example $INSTALL_DIR/bin/process-requests.sh
344+
chmod +x $INSTALL_DIR/bin/process-requests.sh
368345

369346
echo "..."
370347
echo "Instalação completa!"

0 commit comments

Comments
 (0)