Skip to content

Commit

Permalink
Use poetry for running celery, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
theskumar committed Dec 20, 2023
1 parent 2a7a93b commit 40ae7fe
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 21 deletions.
2 changes: 1 addition & 1 deletion hooks/post_gen_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ green=`tput setaf 2`
reset=`tput sgr0`

# Ensure newline at EOF
find . ! -path "*/venv/*" -type f -name "*.py" -exec bash -c "tail -n1 {} | read -r _ || echo >> {}" \;
find . ! -path "*/.venv/*" -type f -name "*.py" -exec bash -c "tail -n1 {} | read -r _ || echo >> {}" \;

echo "${green}[Finished]${reset}"

Expand Down
2 changes: 0 additions & 2 deletions {{cookiecutter.github_repository}}/provisioner/hosts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ vm=0
user=ubuntu
project_namespace={% raw %}{{ project_name }}-{{ deploy_env }}{% endraw %}
project_path=/home/ubuntu/{% raw %}{{ deploy_env }}{% endraw %}/{{ cookiecutter.github_repository }}
venv_path={% raw %}{{ project_path }}/venv{% endraw %}
use_letsencrypt={{ 'True' if cookiecutter.letsencrypt.lower() == 'y' else 'False' }}
letsencrypt_email={{ cookiecutter.letsencrypt_email }}
django_settings="settings.production"
Expand All @@ -16,7 +15,6 @@ vm=1
deploy_env=vagrant
user=vagrant
project_path=/home/vagrant/{{ cookiecutter.github_repository }}
venv_path=/home/vagrant/venv
django_settings="settings.development"
use_letsencrypt=False
pg_db={{ cookiecutter.main_module }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
file: path={{ celery_log_dir }} state=directory owner={{celery_user}} group={{celery_group}} mode=751 recurse=yes
tags: ['configure', 'celery']

- name: ensure python virtualenv exist
command: python3 -m venv {{ venv_path }} creates={{ venv_path }}
become: false
tags: ['celery']

- name: ensure celery package is installed
pip: name=celery state=present executable={{ venv_path }}/bin/pip
become: false
tags: ['celery']

- name: copy celery service
template: src=celery.service.j2 dest=/etc/systemd/system/celery-{{ project_namespace }}.service
tags: ['celery']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Group={{ celery_group }}
Type=forking
Restart=always
WorkingDirectory={{ project_path }}
ExecStart={{ venv_path }}/bin/celery -A {{ project_name }} multi start worker-{{ project_namespace }} -l {{ celery_log_level }} \
ExecStart=poetry run celery -A {{ project_name }} multi start worker-{{ project_namespace }} -l {{ celery_log_level }} \
--logfile={{ celery_log_file }} --pidfile={{ celery_pid_file }} --schedule={{ celerybeat_schedule_file}}
ExecStop={{ venv_path }}/bin/celery multi stopwait worker-{{ project_namespace }} --pidfile={{ celery_pid_file }}
ExecReload={{ venv_path }}/bin/celery -A {{ project_name }} multi restart worker-{{ project_namespace }} -l {{ celery_log_level }} \
ExecStop=poetry run celery multi stopwait worker-{{ project_namespace }} --pidfile={{ celery_pid_file }}
ExecReload=poetry run celery -A {{ project_name }} multi restart worker-{{ project_namespace }} -l {{ celery_log_level }} \
--logfile={{ celery_log_file }} --pidfile={{ celery_pid_file }} --schedule={{ celerybeat_schedule_file}}

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RuntimeDirectory={{ celery_runtime_dir }}
Group={{ celery_group }}
Restart=always
WorkingDirectory={{ project_path }}
ExecStart={{ venv_path }}/bin/celery -A {{ project_name }} beat -l {{ celery_log_level }} \
ExecStart=poetry run celery -A {{ project_name }} beat -l {{ celery_log_level }} \
--logfile={{ celerybeat_log_file }} --pidfile={{ celerybeat_pid_file }} --schedule={{ celerybeat_schedule_file}}

[Install]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ base_ubuntu:
- python3.9
- python3.9-dev
- python-setuptools
- python3-venv
- python3-pip
- sysstat
- vim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SyslogIdentifier=gunicorn
User={{ asgi_user }}
Group={{ asgi_group }}
WorkingDirectory={{ project_path }}
ExecStart={{ venv_path }}/bin/gunicorn -w {{ asgi_workers }} --bind unix://{{ asgi_socket }} --access-logfile {{project_log_dir}}/asgi.log --capture-output --error-logfile {{project_log_dir}}/asgi-errors.log -k uvicorn.workers.UvicornWorker asgi:application
ExecStart=poetry run gunicorn -w {{ asgi_workers }} --bind unix://{{ asgi_socket }} --access-logfile {{project_log_dir}}/asgi.log --capture-output --error-logfile {{project_log_dir}}/asgi-errors.log -k uvicorn.workers.UvicornWorker asgi:application

[Install]
WantedBy=multi-user.target
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.github_repository}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ django-stubs = "^1.12"
bump2version = "^1.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.isort]
Expand All @@ -148,7 +148,7 @@ default_section = "THIRDPARTY"
import_heading_firstparty = "{{ cookiecutter.project_name }} Stuff"
import_heading_stdlib = "Standard Library"
import_heading_thirdparty = "Third Party Stuff"
skip_glob = ["*/migrations/**", "*/venv/**", "*/docs/**"]
skip_glob = ["*/migrations/**", "*/.venv/**", "*/docs/**"]

[tool.black]
target_version = [ "py38", "py39" ]
Expand Down

0 comments on commit 40ae7fe

Please sign in to comment.