ui / django-post_office

A Django app that allows you to send email asynchronously in Django. Supports HTML email, database backed templates and logging.
MIT License
1.01k stars 268 forks source link

Multiple instances on the same server #458

Closed Mogost closed 5 months ago

Mogost commented 10 months ago

Hi, I have multiple instances of my application deployed on one server. I got the error, stacktrace attached

FileExistsError: [Errno 17] File exists: '/tmp/916412.lock' -> '/tmp/post_office.lock'
  File "celery/app/trace.py", line 760, in __protected_call__
    return self.run(*args, **kwargs)
  File "post_office/tasks.py", line 33, in send_queued_mail
    send_queued_mail_until_done()
  File "post_office/mail.py", line 470, in send_queued_mail_until_done
    with FileLock(lockfile):
  File "post_office/lockfile.py", line 148, in __enter__
    self.acquire()
  File "post_office/lockfile.py", line 128, in acquire
    os.symlink(self.pid_filename, self.lock_filename)

I use celery option. It looks like I cannot fix that problem without monkey-patching this https://github.com/ui/django-post_office/blob/9acc56f2c38f36862c296fea587879dc776f80a8/post_office/lockfile.py#L155 or rewriting tasks https://github.com/ui/django-post_office/blob/9acc56f2c38f36862c296fea587879dc776f80a8/post_office/tasks.py

Ideally name of lock file should be a setting like

POST_OFFICE = {
    "BACKENDS": {
        "default":  ...
    },
    "DEFAULT_PRIORITY": "now",
    "CELERY_ENABLED": True,
    "LOCK_FILE_NAME": "post_office_...",
}
 default_lockfile = os.path.join(tempfile.gettempdir(), settings.LOCK_FILE_NAME) 
Mogost commented 5 months ago

Hi @selwin @jrief, could you please take a look at this?

selwin commented 5 months ago

@Mogost commented on your PR. This is a very useful addition, thanks!

Mogost commented 5 months ago

@selwin could we have a new release for this? It would make my life a little easier.

selwin commented 5 months ago

Will try to make a release this weekend :)

Message ID: @.***>