| Conditions | 4 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | # coding: utf-8 |
||
| 14 | def recycle(): |
||
| 15 | """ |
||
| 16 | the purpose of this tasks is to recycle the data from the cache |
||
| 17 | with version=2 in the main cache |
||
| 18 | """ |
||
| 19 | logger = getLogger('django_th.trigger_happy') |
||
| 20 | all_packages = MyService.all_packages() |
||
| 21 | for package in all_packages: |
||
| 22 | cache = caches[package] |
||
| 23 | # http://niwinz.github.io/django-redis/latest/#_scan_delete_keys_in_bulk |
||
| 24 | for service in cache.iter_keys('th_*'): |
||
| 25 | try: |
||
| 26 | # get the value from the cache version=2 |
||
| 27 | service_value = cache.get(service, version=2) |
||
| 28 | # put it in the version=1 |
||
| 29 | cache.set(service, service_value) |
||
| 30 | # remote version=2 |
||
| 31 | cache.delete_pattern(service, version=2) |
||
| 32 | except ValueError: |
||
| 33 | pass |
||
| 34 | logger.info('recycle of cache done!') |
||
| 35 |