Skip to content

Commit

Permalink
Merge pull request #266 from lekang9/master
Browse files Browse the repository at this point in the history
Update publish_with_cache_flush in common.py
  • Loading branch information
rohanpm committed Mar 21, 2024
2 parents db68722 + de743a1 commit b9f3e78
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
14 changes: 11 additions & 3 deletions pubtools/_pulp/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
from more_executors.futures import f_sequence, f_return

LOG = logging.getLogger("pubtools.pulp")
UNSET = object()


class StepDecorator(object):
"""Implementation of PulpTask.step decorator. See that method for more info."""

def __init__(self, name):
def __init__(self, name, depends_on, skipped_value):
self._name = name
self._depends_on = depends_on or []
self._skipped_value = skipped_value

@property
def human_name(self):
Expand All @@ -28,7 +31,11 @@ def new_fn(instance, *args, **kwargs):
self.human_name,
extra={"event": {"type": "%s-skip" % self.machine_name}},
)
return args[0] if args else None
return (
self._skipped_value
if self._skipped_value is not UNSET
else args[0] if args else None
)

logger = StepLogger(self)
args = logger.log_start(args)
Expand All @@ -53,7 +60,8 @@ def new_fn(instance, *args, **kwargs):

def should_skip(self, instance):
skip = (getattr(instance.args, "skip", None) or "").split(",")
return self.machine_name in skip
deps_and_self = self._depends_on + [self.machine_name]
return any([name in skip for name in deps_and_self])


# helpers used in implementation of decorator
Expand Down
10 changes: 7 additions & 3 deletions pubtools/_pulp/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pubtools.pluggy import task_context

from .step import StepDecorator
from .step import StepDecorator, UNSET


LOG = logging.getLogger("pubtools.pulp")
Expand Down Expand Up @@ -68,13 +68,17 @@ def args(self):
return self._args

@classmethod
def step(cls, name):
def step(cls, name, depends_on=None, skipped_value=UNSET):
"""A decorator to mark an instance method as a discrete workflow step.
Marking a method as a step has effects:
- Log messages will be produced when entering and leaving the method
- The method can be skipped if requested by the caller (via --skip argument)
- Methods that depend on other methods are implicitly skipped if depends_on
is supplied and that dependant is being skipped
- If the method is skipped, it returns either `skipped_value` (if that has
been set), or the method's first argument.
Steps may be written as plain blocking functions, as non-blocking
functions which accept or return Futures, or as generators.
Expand All @@ -94,7 +98,7 @@ def step(cls, name):
- The step is considered *failed* if it raised an exception.
- The step is considered *finished* once all items have been yielded.
"""
return StepDecorator(name)
return StepDecorator(name, depends_on, skipped_value)

def _basic_args(self):
# minimum args required for a pulp CLI task
Expand Down
2 changes: 1 addition & 1 deletion pubtools/_pulp/tasks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class CDNCache(FastPurgeClientService, CdnClientService):
"""Provide features to interact with CDN cache."""

@step("Flush CDN cache")
@step("Flush CDN cache", depends_on=["publish"], skipped_value=[])
def flush_cdn(self, repos):
"""Clears the CDN cache for the repositories provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
{"event": {"type": "publish-skip"}}
{"event": {"type": "flush-ud-cache-start"}}
{"event": {"type": "flush-ud-cache-end"}}
{"event": {"type": "flush-cdn-cache-start"}}
{"event": {"type": "flush-cdn-cache-end"}}
{"event": {"type": "flush-cdn-cache-skip"}}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
[ INFO] Flush UD cache: started
[ INFO] UD cache flush is not enabled.
[ INFO] Flush UD cache: finished
[ INFO] Flush CDN cache: started
[ INFO] CDN cache flush is not enabled.
[ INFO] Flush CDN cache: finished
[ INFO] Flush CDN cache: skipped

0 comments on commit b9f3e78

Please sign in to comment.