Skip to content

Commit

Permalink
Update celery configs
Browse files Browse the repository at this point in the history
  • Loading branch information
agahkarakuzu committed Sep 4, 2024
1 parent 0660a4b commit 4185b6d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
14 changes: 6 additions & 8 deletions api/neurolibre_celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,15 @@ def start(self, message=""):

def fail(self, message):
self.screening.respond().FAILURE(message)
raise self.task_failure(message)

def succeed(self, message):
self.screening.respond().SUCCESS(message)

def task_failure(self, message):
return states.FAILURE, {
self.update_state(state=states.FAILURE, meta={
'exc_type': f"{JOURNAL_NAME} celery exception",
'exc_message': "Custom",
'message': message
}
})
raise Ignore()

def succeed(self, message):
self.screening.respond().SUCCESS(message)

def update_state(self, state, meta):
self.celery_task.update_state(state=state, meta=meta)
Expand Down
3 changes: 3 additions & 0 deletions api/start_celery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
source ${VENV_PATH}/bin/activate
exec "$@"
43 changes: 43 additions & 0 deletions systemd/default/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## This file is used to configure the Celery service.

It should be placed in the /etc/default directory.

### Environment variables

- `CELERYD_NODES`: The nodes to start.
- `CELERY_BIN`: The path to the Celery binary.
- `CELERY_APP`: The name of the Celery app.
- `CELERYD_MULTI`: The multi command.
- `CELERYD_OPTS`: The options to pass to the Celery command.
- `CELERYD_PID_FILE`: The path to the PID file.
- `CELERYD_LOG_FILE`: The path to the log file.
- `CELERYD_LOG_LEVEL`: The log level.

### Notes

- Make sure to set the correct permissions for the `start_celery.sh` script.

```bash
chmod +x /home/ubuntu/full-stack-server/api/start_celery.sh
```

- sudo chown ubuntu:ubuntu /etc/default/celery
- sudo chmod 644 /etc/default/celery

Remember to reload the systemd daemon after making changes to the service files.

```bash
sudo systemctl daemon-reload
```

If you encounter errors, check the status of the service with:

```bash
sudo systemctl status <service-name>
```

And check the logs with:

```bash
sudo journalctl -u <service-name> -f
```
9 changes: 9 additions & 0 deletions systemd/default/celery
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
VENV_PATH="/home/ubuntu/venv/neurolibre38"
CELERY_BIN="${VENV_PATH}/bin/celery"
CELERYD_NODES="w1 w2"
CELERY_APP="neurolibre_celery_tasks"
CELERYD_MULTI="multi"
CELERYD_OPTS="--time-limit=300 --concurrency=8"
CELERYD_PID_FILE="/home/ubuntu/full-stack-server/api/celery_preview/run/celery/%n.pid"
CELERYD_LOG_FILE="/home/ubuntu/full-stack-server/api/celery_preview/log/celery/%n%I.log"
CELERYD_LOG_LEVEL="INFO"
13 changes: 7 additions & 6 deletions systemd/preview_celery.service
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[Unit]
Description=Neurolibre Task Manager
After=neurolibre-preview.service
After=network.target

[Service]
Type=forking
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/full-stack-server/api
EnvironmentFile=-/etc/default/celery
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${VENV_PATH}/bin"
Environment=GIT_PYTHON_GIT_EXECUTABLE=/usr/bin/git
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ubuntu/venv/neurolibre/bin
Environment="CELERY_CREATE_DIRS=1"
ExecStart=/home/ubuntu/venv/neurolibre/bin/celery -A neurolibre_celery_tasks multi start w1 w2 --loglevel=info --pidfile="celery_preview/run/%n.pid" --logfile="celery_preview/log/%n%I.log"
ExecStop=/home/ubuntu/venv/neurolibre/bin/celery -A neurolibre_celery_tasks multi stopwait w1 w2
ExecReload=/home/ubuntu/venv/neurolibre/bin/celery -A neurolibre_celery_tasks multi restart w1 w2 --loglevel=info --pidfile="celery_preview/run/%n.pid" --logfile="celery_preview/log/%n%I.log"
Environment=CELERY_CREATE_DIRS=1
ExecStart=/home/ubuntu/full-stack-server/api/start_celery.sh ${CELERY_BIN} -A ${CELERY_APP} multi start ${CELERYD_NODES} --loglevel=${CELERYD_LOG_LEVEL} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} ${CELERYD_OPTS}
ExecStop=/home/ubuntu/full-stack-server/api/start_celery.sh ${CELERY_BIN} -A ${CELERY_APP} multi stopwait ${CELERYD_NODES}
ExecReload=/home/ubuntu/full-stack-server/api/start_celery.sh ${CELERY_BIN} -A ${CELERY_APP} multi restart ${CELERYD_NODES} --loglevel=${CELERYD_LOG_LEVEL} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} ${CELERYD_OPTS}
Restart=on-failure

[Install]
Expand Down

0 comments on commit 4185b6d

Please sign in to comment.