We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
502 error on category pages
We can reproduce it with code below.

Seems it's connected with https://github.com/fidals/shopelectro/issues/648, but it's not checked yet

```
import requests

BASE = 'https://www.shopelectro.ru'

broken_urls = []
for c in CategoryPage.objects.all():
	response = requests.get(BASE + c.url)
	if response.status_code != 200:
		broken_urls += (response.status_code, response.url)

print('\n'.join((str(url) for url in broken_urls)))

---

# output:
502
https://www.shopelectro.ru/catalog/categories/batarei-saliutov-moshchnye/
502
https://www.shopelectro.ru/catalog/categories/khlopushki-pnevmaticheskie/
502
https://www.shopelectro.ru/catalog/categories/izmeritelnye-pribory-211/
502
https://www.shopelectro.ru/catalog/categories/dlia-tiporazmera-aaaaa/
502
https://www.shopelectro.ru/catalog/categories/tiporazmer-aa/
502
https://www.shopelectro.ru/catalog/categories/tiporazmer-6f22/
502
https://www.shopelectro.ru/catalog/categories/invertory/
502
https://www.shopelectro.ru/catalog/categories/palchikovye-aa-r6-lr6-fr6-316/
502
https://www.shopelectro.ru/catalog/categories/mizinchikovye-aaa-r03-lr03-fr03-286/
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `shopelectro/celery.py`
Content:
```
1 from __future__ import absolute_import, unicode_literals
2 from datetime import timedelta
3 import os
4 
5 from celery import Celery
6 from kombu import Exchange, Queue
7 
8 # set the default Django settings module for the 'celery' program.
9 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shopelectro.settings.local')
10 
11 app = Celery('shopelectro')
12 
13 # Exchanges
14 default_exchange = Exchange('default', type='direct')
15 utils_exchange = Exchange('utils', type='direct')
16 
17 # http://docs.celeryproject.org/en/latest/userguide/tasks.html
18 task_queues = (
19     Queue(
20         name='default',
21         exchange=default_exchange,
22         routing_key='default',
23     ),
24     Queue(
25         name='mail',
26         exchange=utils_exchange,
27         routing_key='utils.mail',
28     ),
29     Queue(
30         name='command',
31         exchange=utils_exchange,
32         routing_key='utils.command',
33     )
34 )
35 
36 # http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html
37 beat_schedule = {
38     'update-catalog': {
39         'task': 'shopelectro.tasks.update_catalog',
40         'schedule': timedelta(hours=2).total_seconds(),
41     },
42     'check-purchase': {
43         'task': 'shopelectro.tasks.check_purchase',
44         'schedule': timedelta(days=1).total_seconds(),
45     },
46 }
47 
48 # http://docs.celeryproject.org/en/master/userguide/routing.html
49 task_routes = {
50     'shopelectro.tasks.update_catalog': {
51         'queue': 'command',
52         'routing_key': 'utils.command',
53         'priority': 30,
54     },
55     'shopelectro.tasks.check_purchase': {
56         'queue': 'command',
57         'routing_key': 'utils.command',
58         'priority': 20,
59     },
60     'ecommerce.tasks.send_mail': {
61         'queue': 'mail',
62         'routing_key': 'utils.mail',
63         'priority': 50,
64     },
65 }
66 
67 # Using a string here means the worker don't have to serialize
68 # the configuration object to child processes.
69 # - namespace='CELERY' means all celery-related configuration keys
70 #   should have a `CELERY_` prefix.
71 app.config_from_object('django.conf:settings', namespace='CELERY')
72 
73 # http://docs.celeryproject.org/en/latest/userguide/configuration.html
74 
75 BROCKER_URL = (
76     f'amqp://{os.environ["RABBITMQ_DEFAULT_USER"]}:{os.environ["RABBITMQ_DEFAULT_PASS"]}'
77     f'@{os.environ["RABBITMQ_URL"]}:{os.environ["RABBITMQ_PORT"]}/'
78 )
79 app.conf.update(
80     broker_url=BROCKER_URL,
81     broker_heartbeat=30,
82     task_acks_late=True,
83     task_default_queue='default',
84     task_default_exchange='default',
85     task_default_routing_key='default',
86     task_ignore_result=True,
87     worker_pool_restarts=1000,
88     task_routes=task_routes,
89     task_queues=task_queues,
90     beat_schedule=beat_schedule,
91 )
92 
93 # Load task modules from all registered Django app configs.
94 app.autodiscover_tasks()
95
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/shopelectro/celery.py b/shopelectro/celery.py
--- a/shopelectro/celery.py
+++ b/shopelectro/celery.py
@@ -83,11 +83,11 @@
     task_default_queue='default',
     task_default_exchange='default',
     task_default_routing_key='default',
-    task_ignore_result=True,
-    worker_pool_restarts=1000,
+    worker_pool_restarts=True,
     task_routes=task_routes,
     task_queues=task_queues,
     beat_schedule=beat_schedule,
+    worker_max_memory_per_child=200000,  # after 250MB will restart
 )
 
 # Load task modules from all registered Django app configs.

{"golden_diff": "diff --git a/shopelectro/celery.py b/shopelectro/celery.py\n--- a/shopelectro/celery.py\n+++ b/shopelectro/celery.py\n@@ -83,11 +83,11 @@\n     task_default_queue='default',\n     task_default_exchange='default',\n     task_default_routing_key='default',\n-    task_ignore_result=True,\n-    worker_pool_restarts=1000,\n+    worker_pool_restarts=True,\n     task_routes=task_routes,\n     task_queues=task_queues,\n     beat_schedule=beat_schedule,\n+    worker_max_memory_per_child=200000,  # after 250MB will restart\n )\n \n # Load task modules from all registered Django app configs.\n", "issue": "502 error on category pages\nWe can reproduce it with code below.\r\n\r\nSeems it's connected with https://github.com/fidals/shopelectro/issues/648, but it's not checked yet\r\n\r\n```\r\nimport requests\r\n\r\nBASE = 'https://www.shopelectro.ru'\r\n\r\nbroken_urls = []\r\nfor c in CategoryPage.objects.all():\r\n\tresponse = requests.get(BASE + c.url)\r\n\tif response.status_code != 200:\r\n\t\tbroken_urls += (response.status_code, response.url)\r\n\r\nprint('\\n'.join((str(url) for url in broken_urls)))\r\n\r\n---\r\n\r\n# output:\r\n502\r\nhttps://www.shopelectro.ru/catalog/categories/batarei-saliutov-moshchnye/\r\n502\r\nhttps://www.shopelectro.ru/catalog/categories/khlopushki-pnevmaticheskie/\r\n502\r\nhttps://www.shopelectro.ru/catalog/categories/izmeritelnye-pribory-211/\r\n502\r\nhttps://www.shopelectro.ru/catalog/categories/dlia-tiporazmera-aaaaa/\r\n502\r\nhttps://www.shopelectro.ru/catalog/categories/tiporazmer-aa/\r\n502\r\nhttps://www.shopelectro.ru/catalog/categories/tiporazmer-6f22/\r\n502\r\nhttps://www.shopelectro.ru/catalog/categories/invertory/\r\n502\r\nhttps://www.shopelectro.ru/catalog/categories/palchikovye-aa-r6-lr6-fr6-316/\r\n502\r\nhttps://www.shopelectro.ru/catalog/categories/mizinchikovye-aaa-r03-lr03-fr03-286/\r\n```\n", "before_files": [{"content": "from __future__ import absolute_import, unicode_literals\nfrom datetime import timedelta\nimport os\n\nfrom celery import Celery\nfrom kombu import Exchange, Queue\n\n# set the default Django settings module for the 'celery' program.\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shopelectro.settings.local')\n\napp = Celery('shopelectro')\n\n# Exchanges\ndefault_exchange = Exchange('default', type='direct')\nutils_exchange = Exchange('utils', type='direct')\n\n# http://docs.celeryproject.org/en/latest/userguide/tasks.html\ntask_queues = (\n    Queue(\n        name='default',\n        exchange=default_exchange,\n        routing_key='default',\n    ),\n    Queue(\n        name='mail',\n        exchange=utils_exchange,\n        routing_key='utils.mail',\n    ),\n    Queue(\n        name='command',\n        exchange=utils_exchange,\n        routing_key='utils.command',\n    )\n)\n\n# http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html\nbeat_schedule = {\n    'update-catalog': {\n        'task': 'shopelectro.tasks.update_catalog',\n        'schedule': timedelta(hours=2).total_seconds(),\n    },\n    'check-purchase': {\n        'task': 'shopelectro.tasks.check_purchase',\n        'schedule': timedelta(days=1).total_seconds(),\n    },\n}\n\n# http://docs.celeryproject.org/en/master/userguide/routing.html\ntask_routes = {\n    'shopelectro.tasks.update_catalog': {\n        'queue': 'command',\n        'routing_key': 'utils.command',\n        'priority': 30,\n    },\n    'shopelectro.tasks.check_purchase': {\n        'queue': 'command',\n        'routing_key': 'utils.command',\n        'priority': 20,\n    },\n    'ecommerce.tasks.send_mail': {\n        'queue': 'mail',\n        'routing_key': 'utils.mail',\n        'priority': 50,\n    },\n}\n\n# Using a string here means the worker don't have to serialize\n# the configuration object to child processes.\n# - namespace='CELERY' means all celery-related configuration keys\n#   should have a `CELERY_` prefix.\napp.config_from_object('django.conf:settings', namespace='CELERY')\n\n# http://docs.celeryproject.org/en/latest/userguide/configuration.html\n\nBROCKER_URL = (\n    f'amqp://{os.environ[\"RABBITMQ_DEFAULT_USER\"]}:{os.environ[\"RABBITMQ_DEFAULT_PASS\"]}'\n    f'@{os.environ[\"RABBITMQ_URL\"]}:{os.environ[\"RABBITMQ_PORT\"]}/'\n)\napp.conf.update(\n    broker_url=BROCKER_URL,\n    broker_heartbeat=30,\n    task_acks_late=True,\n    task_default_queue='default',\n    task_default_exchange='default',\n    task_default_routing_key='default',\n    task_ignore_result=True,\n    worker_pool_restarts=1000,\n    task_routes=task_routes,\n    task_queues=task_queues,\n    beat_schedule=beat_schedule,\n)\n\n# Load task modules from all registered Django app configs.\napp.autodiscover_tasks()\n", "path": "shopelectro/celery.py"}], "after_files": [{"content": "from __future__ import absolute_import, unicode_literals\nfrom datetime import timedelta\nimport os\n\nfrom celery import Celery\nfrom kombu import Exchange, Queue\n\n# set the default Django settings module for the 'celery' program.\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shopelectro.settings.local')\n\napp = Celery('shopelectro')\n\n# Exchanges\ndefault_exchange = Exchange('default', type='direct')\nutils_exchange = Exchange('utils', type='direct')\n\n# http://docs.celeryproject.org/en/latest/userguide/tasks.html\ntask_queues = (\n    Queue(\n        name='default',\n        exchange=default_exchange,\n        routing_key='default',\n    ),\n    Queue(\n        name='mail',\n        exchange=utils_exchange,\n        routing_key='utils.mail',\n    ),\n    Queue(\n        name='command',\n        exchange=utils_exchange,\n        routing_key='utils.command',\n    )\n)\n\n# http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html\nbeat_schedule = {\n    'update-catalog': {\n        'task': 'shopelectro.tasks.update_catalog',\n        'schedule': timedelta(hours=2).total_seconds(),\n    },\n    'check-purchase': {\n        'task': 'shopelectro.tasks.check_purchase',\n        'schedule': timedelta(days=1).total_seconds(),\n    },\n}\n\n# http://docs.celeryproject.org/en/master/userguide/routing.html\ntask_routes = {\n    'shopelectro.tasks.update_catalog': {\n        'queue': 'command',\n        'routing_key': 'utils.command',\n        'priority': 30,\n    },\n    'shopelectro.tasks.check_purchase': {\n        'queue': 'command',\n        'routing_key': 'utils.command',\n        'priority': 20,\n    },\n    'ecommerce.tasks.send_mail': {\n        'queue': 'mail',\n        'routing_key': 'utils.mail',\n        'priority': 50,\n    },\n}\n\n# Using a string here means the worker don't have to serialize\n# the configuration object to child processes.\n# - namespace='CELERY' means all celery-related configuration keys\n#   should have a `CELERY_` prefix.\napp.config_from_object('django.conf:settings', namespace='CELERY')\n\n# http://docs.celeryproject.org/en/latest/userguide/configuration.html\n\nBROCKER_URL = (\n    f'amqp://{os.environ[\"RABBITMQ_DEFAULT_USER\"]}:{os.environ[\"RABBITMQ_DEFAULT_PASS\"]}'\n    f'@{os.environ[\"RABBITMQ_URL\"]}:{os.environ[\"RABBITMQ_PORT\"]}/'\n)\napp.conf.update(\n    broker_url=BROCKER_URL,\n    broker_heartbeat=30,\n    task_acks_late=True,\n    task_default_queue='default',\n    task_default_exchange='default',\n    task_default_routing_key='default',\n    worker_pool_restarts=True,\n    task_routes=task_routes,\n    task_queues=task_queues,\n    beat_schedule=beat_schedule,\n    worker_max_memory_per_child=200000,  # after 250MB will restart\n)\n\n# Load task modules from all registered Django app configs.\napp.autodiscover_tasks()\n", "path": "shopelectro/celery.py"}]}