Some emails do not send, in Error Log: "Communication not found"

some emails do not send with error frappe.exceptions.DoesNotExistError: Communication 178befe608 not found`

Email sending unstabile: about 60% emails was sent without error, but 40% emails gets error “Communication 178befe608 not found”

I think the problem is in the sequence of scheduled tasks, sometimes Communication has time to be created and then this message can be sent by Email Queue.

Sometimes the message doesn’t have time to be prepared and then another process “Email Queue” tries to send a Communication which hasn’t been created yet and then an error occurs.

bench --site erp.sitename.com enable-scheduler:
-----------------------------------------------------------------
Enabled for erp.sitename.com


bench doctor output:
-----------------------------------------------------------------
-----Checking scheduler status-----
Workers online: 3
-----erp.sitename.com Jobs-----

Error Log output:

`20:52:26 Traceback (most recent call last):
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/rq/worker.py", line 1013, in perform_job
    rv = job.perform()
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/rq/job.py", line 709, in perform
    self._result = self._execute()
  File "/home/erpnext/frappe-bench/env/lib/python3.8/site-packages/rq/job.py", line 732, in _execute
    result = self.func(*self.args, **self.kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/background_jobs.py", line 99, in execute_job
    method(**kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py", line 458, in sendmail
    communication = frappe.get_doc("Communication", communication_name)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 855, in get_doc
    doc = frappe.model.document.get_doc(*args, **kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 75, in get_doc
    return controller(*args, **kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 113, in __init__
    self.load_from_db()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 156, in load_from_db
    frappe.throw(_("{0} {1} not found").format(_(self.doctype), self.name), frappe.DoesNotExistError)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 437, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 416, in msgprint
    _raise_exception()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 370, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.DoesNotExistError: Communication 178befe608 not found`

Facing similar issue, have raised a GitHub issue.

This release resolved problem.
https://github.com/frappe/frappe/releases/tag/v13.12.0
After update and test, all emails was sent.