{"action":"created","issue":{"url":"https://api.github.com/repos/translate/pootle/issues/4094","labels_url":"https://api.github.com/repos/translate/pootle/issues/4094/labels{/name}","comments_url":"https://api.github.com/repos/translate/pootle/issues/4094/comments","events_url":"https://api.github.com/repos/translate/pootle/issues/4094/events","html_url":"https://github.com/translate/pootle/issues/4094","id":107748225,"number":4094,"title":"Stats: RQ fails jobs if no jobs were executed during more than MySQL `wait_timeout` time","user":{"login":"ta2-1","id":682845,"avatar_url":"https://avatars.githubusercontent.com/u/682845?v=3","gravatar_id":"","url":"https://api.github.com/users/ta2-1","html_url":"https://github.com/ta2-1","followers_url":"https://api.github.com/users/ta2-1/followers","following_url":"https://api.github.com/users/ta2-1/following{/other_user}","gists_url":"https://api.github.com/users/ta2-1/gists{/gist_id}","starred_url":"https://api.github.com/users/ta2-1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ta2-1/subscriptions","organizations_url":"https://api.github.com/users/ta2-1/orgs","repos_url":"https://api.github.com/users/ta2-1/repos","events_url":"https://api.github.com/users/ta2-1/events{/privacy}","received_events_url":"https://api.github.com/users/ta2-1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-22T16:12:46Z","updated_at":"2015-09-22T16:20:48Z","closed_at":null,"body":"We get `OperationalError: (2006, 'MySQL server has gone away') ` every time we touch (do something that causes stats refreshing) our staging server after long break. \r\nTo reproduce:\r\n- set MySQL `wait_timeout` variable to 10 seconds (or any value you are able to wait);\r\n- start `rqworker`;\r\n- add or change a translation for any unit;\r\n- check that stats were refreshed;\r\n- wait a little bit more than 10 seconds;\r\n- add or change a translation for any unit;\r\n- stats were not refreshed, last RQ job failed.\r\n"},"comment":{"url":"https://api.github.com/repos/translate/pootle/issues/comments/142339103","html_url":"https://github.com/translate/pootle/issues/4094#issuecomment-142339103","issue_url":"https://api.github.com/repos/translate/pootle/issues/4094","id":142339103,"user":{"login":"ta2-1","id":682845,"avatar_url":"https://avatars.githubusercontent.com/u/682845?v=3","gravatar_id":"","url":"https://api.github.com/users/ta2-1","html_url":"https://github.com/ta2-1","followers_url":"https://api.github.com/users/ta2-1/followers","following_url":"https://api.github.com/users/ta2-1/following{/other_user}","gists_url":"https://api.github.com/users/ta2-1/gists{/gist_id}","starred_url":"https://api.github.com/users/ta2-1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ta2-1/subscriptions","organizations_url":"https://api.github.com/users/ta2-1/orgs","repos_url":"https://api.github.com/users/ta2-1/repos","events_url":"https://api.github.com/users/ta2-1/events{/privacy}","received_events_url":"https://api.github.com/users/ta2-1/received_events","type":"User","site_admin":false},"created_at":"2015-09-22T16:20:48Z","updated_at":"2015-09-22T16:20:48Z","body":"As described in [Django ticket 15119](https://code.djangoproject.com/ticket/15119), we can see that Django was making a ping to validate if the connection was alive before executing every query. This behavior was fixed in [commit 282b2f4](https://github.com/django/django/commit/282b2f40cd0aa09815001e178f60c9e71667d847).\r\n\r\nDjango developers gave one short answer for all questions like this in https://code.djangoproject.com/ticket/21597#comment:29\r\n\r\nTherefore `rqworker` process should validate connection itself for each new job.\r\n(Note: if we close a connection then Django will create a new one).\r\n\r\nI’d suggest to use Django per request approach for jobs and call `django.db.close_old_connections()` before and after every job."}}