edx/configuration — pull request #1756 by bdero (2014-12-22 07:34:34+00:00)
Title: Fix edxapp not restarting

This fixes an issue where edxapp doesn't restart when deploying using playbooks that run the edxapp role twice (once for the celery workers, and once for the LMS and CMS).

When a role is run in ansible, it seems that the state of handlers is kept in the scope of the play. Once a `when` clause for a handler has been evaluated (which seems to happen at the end of each role by default, even though they're not flushed until the end of the play), it is never evaluated again during that play, even when the handler is notified and executed after already having been flushed.

For instance, in the vagrant-fullstack playbook, the edxapp role is executed twice as follows:
```yaml
- { role: 'edxapp', celery_worker: True }
- edxapp
```
..which results in the edxapp and edxapp_worker restart handlers being executed only once at the end of the play:
```
NOTIFIED: [edxapp | restart edxapp] *******************************************
skipping: [192.168.30.10] => (item=lms)
skipping: [192.168.30.10] => (item=cms)

NOTIFIED: [edxapp | restart edxapp_workers] ***********************************
changed: [192.168.30.10] => (item={'queue': 'low', 'service_variant': 'cms', 'concurrency': 3})
changed: [192.168.30.10] => (item={'queue': 'default', 'service_variant': 'cms', 'concurrency': 4})
changed: [192.168.30.10] => (item={'queue': 'high', 'service_variant': 'cms', 'concurrency': 1})
changed: [192.168.30.10] => (item={'queue': 'low', 'service_variant': 'lms', 'concurrency': 1})
changed: [192.168.30.10] => (item={'queue': 'default', 'service_variant': 'lms', 'concurrency': 3})
changed: [192.168.30.10] => (item={'queue': 'high', 'service_variant': 'lms', 'concurrency': 4})
changed: [192.168.30.10] => (item={'queue': 'high_mem', 'service_variant': 'lms', 'concurrency': 2})
```
Well, what we really want is to have both the apps and the workers restart, so we'll need to flush the handlers at the end of the edxapp role. So let's say we add the task `meta: flush_handlers` to the end of deploy.yml in the edxapp role.
The result is that the restart handlers now run twice, but both as if celery_worker is defined (like above), even though it's not while the second role is executing.

The fix is to just turn the two handlers into tasks, since they're *always* executed whenever the edxapp role is run anyhow.