Set timestamp ONLY after slapgrid thinks it's okay (promises, ...)

parent 405bf76f
...@@ -406,11 +406,6 @@ class Partition(object): ...@@ -406,11 +406,6 @@ class Partition(object):
partition_supervisor_configuration) partition_supervisor_configuration)
self.updateSupervisor() self.updateSupervisor()
parameter_dict = self.computer_partition.getInstanceParameterDict()
if 'timestamp' in parameter_dict:
timestamp_path = os.path.join(self.instance_path, '.timestamp')
open(timestamp_path, 'w').write(parameter_dict['timestamp'])
def start(self): def start(self):
"""Asks supervisord to start the instance. If this instance is not """Asks supervisord to start the instance. If this instance is not
installed, we install it. installed, we install it.
......
...@@ -603,19 +603,29 @@ class Slapgrid(object): ...@@ -603,19 +603,29 @@ class Slapgrid(object):
clean_run = True clean_run = True
for computer_partition in self.getComputerPartitionList(): for computer_partition in self.getComputerPartitionList():
computer_partition_id = computer_partition.getId() computer_partition_id = computer_partition.getId()
# Check if we defined explicit list of partitions to process.
# If so, if current partition not in this list, skip.
if len(self.computer_partition_filter_list) > 0 and \ if len(self.computer_partition_filter_list) > 0 and \
(computer_partition_id not in self.computer_partition_filter_list): (computer_partition_id not in self.computer_partition_filter_list):
continue continue
instance_path = os.path.join( instance_path = os.path.join(self.instance_root, computer_partition_id)
self.instance_root, computer_partition_id)
# Try to get partition timestamp (last modification date)
timestamp_path = os.path.join(instance_path, '.timestamp') timestamp_path = os.path.join(instance_path, '.timestamp')
parameter_dict = computer_partition.getInstanceParameterDict()
if 'timestamp' in parameter_dict:
timestamp = parameter_dict['timestamp']
else:
timestamp = None
# Check if timestamp from server is more recent than local one.
# If not: it's not worth processing this partition (nothing has changed).
if computer_partition_id not in self.computer_partition_filter_list and \ if computer_partition_id not in self.computer_partition_filter_list and \
(not self.develop) and os.path.exists(timestamp_path): (not self.develop) and os.path.exists(timestamp_path):
old_timestamp = open(timestamp_path).read() old_timestamp = open(timestamp_path).read()
parameter_dict = computer_partition.getInstanceParameterDict() if timestamp:
if 'timestamp' in parameter_dict:
timestamp = parameter_dict['timestamp']
try: try:
if int(timestamp) <= int(old_timestamp): if int(timestamp) <= int(old_timestamp):
continue continue
...@@ -643,7 +653,6 @@ class Slapgrid(object): ...@@ -643,7 +653,6 @@ class Slapgrid(object):
software_release_url=software_url, software_release_url=software_url,
certificate_repository_path=self.certificate_repository_path, certificate_repository_path=self.certificate_repository_path,
console=self.console, buildout=self.buildout) console=self.console, buildout=self.buildout)
# There are no conditions to try to instanciate partition
try: try:
computer_partition_state = computer_partition.getState() computer_partition_state = computer_partition.getState()
if computer_partition_state == "started": if computer_partition_state == "started":
...@@ -672,6 +681,10 @@ class Slapgrid(object): ...@@ -672,6 +681,10 @@ class Slapgrid(object):
(computer_partition_id, computer_partition_state) (computer_partition_id, computer_partition_state)
computer_partition.error(error_string) computer_partition.error(error_string)
raise NotImplementedError(error_string) raise NotImplementedError(error_string)
# If partition has been successfully processed, write timestamp
if timestamp:
timestamp_path = os.path.join(instance_path, '.timestamp')
open(timestamp_path, 'w').write(timestamp)
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
exception = traceback.format_exc() exception = traceback.format_exc()
computer_partition.error(exception) computer_partition.error(exception)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment