Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame^] | 1 | import os |
| 2 | import base64 |
| 3 | from planetstack.config import Config |
| 4 | |
| 5 | class SyncStep: |
| 6 | """ A PlanetStack Sync step. |
| 7 | |
| 8 | Attributes: |
| 9 | psmodel Model name the step synchronizes |
| 10 | dependencies list of names of models that must be synchronized first if the current model depends on them |
| 11 | """ |
| 12 | slow=False |
| 13 | def get_prop(prop): |
| 14 | try: |
| 15 | sync_config_dir = Config().sync_config_dir |
| 16 | except: |
| 17 | sync_config_dir = '/etc/planetstack/sync' |
| 18 | prop_config_path = '/'.join(sync_config_dir,self.name,prop) |
| 19 | return open(prop_config_path).read().rstrip() |
| 20 | |
| 21 | def __init__(self, **args): |
| 22 | """Initialize a sync step |
| 23 | Keyword arguments: |
| 24 | name -- Name of the step |
| 25 | provides -- PlanetStack models sync'd by this step |
| 26 | """ |
| 27 | try: |
| 28 | self.soft_deadline = int(self.get_prop('soft_deadline_seconds')) |
| 29 | except: |
| 30 | self.soft_deadline = 5 # 5 seconds |
| 31 | |
| 32 | return |
| 33 | |
| 34 | def fetch_pending(self): |
| 35 | return Sliver.objects.filter(ip=None) |
| 36 | |
| 37 | def call(self): |
| 38 | return True |
| 39 | |
| 40 | def __call__(self): |
| 41 | return self.call() |