Skip to content

Commit

Permalink
Re-implement --tail flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ejholmes committed Jan 27, 2018
1 parent cc941be commit 3cb4918
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion stacker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@


def plan(description=None, action=None,
tail=None,
stacks=None, stack_names=None,
reverse=False):
"""A simple helper that builds a graph based plan from a set of stacks."""

steps = [
Step(stack, fn=action)
Step(stack, fn=action, watch_func=tail)
for stack in stacks]

return build_plan(
Expand Down
1 change: 1 addition & 0 deletions stacker/actions/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ def _generate_plan(self, tail=False):
return plan(
description="Create/Update stacks",
action=self._launch_stack,
tail=self.provider.tail_stack if tail else None,
stacks=self.context.get_stacks(),
stack_names=self.context.stack_names)

Expand Down
1 change: 1 addition & 0 deletions stacker/actions/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _generate_plan(self, tail=False):
return plan(
description="Destroy stacks",
action=self._destroy_stack,
tail=self.provider.tail_stack if tail else None,
stacks=self.context.get_stacks(),
stack_names=self.context.stack_names,
reverse=True)
Expand Down
23 changes: 19 additions & 4 deletions stacker/plan2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import time
import uuid
import multiprocessing

from .actions.base import stack_template_key_name
from .exceptions import (
Expand Down Expand Up @@ -33,11 +34,12 @@ class Step(object):
with this step
"""

def __init__(self, stack, fn=None):
def __init__(self, stack, fn=None, watch_func=None):
self.stack = stack
self.status = PENDING
self.last_updated = time.time()
self.fn = fn
self.watch_func = watch_func

def __repr__(self):
return "<stacker.plan.Step:%s>" % (self.stack.fqn,)
Expand All @@ -49,9 +51,22 @@ def run(self):

log_status(self.name, self.status)

while not self.done:
status = self.fn(self.stack, status=self.status)
self.set_status(status)
watcher = None
if self.watch_func:
watcher = multiprocessing.Process(
target=self.watch_func,
args=(self.stack,)
)
watcher.start()

try:
while not self.done:
status = self.fn(self.stack, status=self.status)
self.set_status(status)
finally:
if watcher and watcher.is_alive():
watcher.terminate()
watcher.join()
return self.ok

@property
Expand Down

0 comments on commit 3cb4918

Please sign in to comment.