3 from planetstack.config import Config
5 class FailedDependency(Exception):
9 """ A PlanetStack Sync step.
12 psmodel Model name the step synchronizes
13 dependencies list of names of models that must be synchronized first if the current model depends on them
18 sync_config_dir = Config().sync_config_dir
20 sync_config_dir = '/etc/planetstack/sync'
21 prop_config_path = '/'.join(sync_config_dir,self.name,prop)
22 return open(prop_config_path).read().rstrip()
24 def __init__(self, **args):
25 """Initialize a sync step
27 name -- Name of the step
28 provides -- PlanetStack models sync'd by this step
31 self.driver = args.get('driver')
33 self.soft_deadline = int(self.get_prop('soft_deadline_seconds'))
35 self.soft_deadline = 5 # 5 seconds
39 def fetch_pending(self):
40 return Sliver.objects.filter(ip=None)
42 def check_dependencies(self, obj):
43 for dep in self.dependencies:
44 peer_object = getattr(obj, dep.name.lowercase())
45 if (peer_object.pk==dep.pk):
46 raise DependencyFailed
48 def call(self, failed=[]):
49 pending = self.fetch_pending()
51 if (not self.depends_on(o, failed)):
53 check_dependencies(o) # Raises exception if failed
55 o.enacted = datetime.now() # Is this the same timezone? XXX
56 o.save(update_fields=['enacted'])