Skip to main content

Code Snippets and How-Tos

Adding backend PYPI packages
  1. Add the package name to the end of the server/requirements.in file
  2. Run the following command:
pip-compile

Now the server/requirements.txt file is updated with proper versions based on the packages specified in server/requirements.in.

  1. Restart the server to reflect the changes updated in server/requirements.txt.
Retry Celery Task

Note: A button in Djago Admin Panel is planned to be added to retry a failed task easier.

Task ids are uuid-shaped, they look like this: 43fd5ac7-ca45-40a8-ad0e-79800d7e4a23 Use the following function to retry (this function was tested):

import ast
from ghost.celery import app

def retry_task(task_id):
meta = app.backend.get_task_meta(task_id)
task_name = meta['task_name']
task = app.tasks[task_name]
args = ast.literal_eval(meta['args'])
return task.apply_async(args=args)

The returned value from the function is also a task so retry_task("43fd5ac7-ca45-40a8-ad0e-79800d7e4a23").id would be the id of the retrying task with id "43fd5ac7-ca45-40a8-ad0e-79800d7e4a23". Maybe log that or show a toast message in the admin panel if possible (logging if totally fine if it's too much of a hassle to do toasts)