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