MCPcopy
hub / github.com/saltstack/salt / check_pause

Method check_pause

salt/state.py:2772–2817  ·  view source on GitHub ↗

Check to see if this low chunk has been paused

(self, low: LowChunk)

Source from the content-addressed store, hash-verified

2770 return False
2771
2772 def check_pause(self, low: LowChunk) -> str | None:
2773 """
2774 Check to see if this low chunk has been paused
2775 """
2776 if not self.jid:
2777 # Can't pause on salt-ssh since we can't track continuous state
2778 return
2779 pause_path = os.path.join(self.opts["cachedir"], "state_pause", self.jid)
2780 start = time.time()
2781 if os.path.isfile(pause_path):
2782 try:
2783 while True:
2784 tries = 0
2785 with salt.utils.files.fopen(pause_path, "rb") as fp_:
2786 try:
2787 pdat = msgpack_deserialize(fp_.read())
2788 except salt.utils.msgpack.exceptions.UnpackValueError:
2789 # Reading race condition
2790 if tries > 10:
2791 # Break out if there are a ton of read errors
2792 return
2793 tries += 1
2794 time.sleep(1)
2795 continue
2796 id_ = low["__id__"]
2797 key = ""
2798 if id_ in pdat:
2799 key = id_
2800 elif "__all__" in pdat:
2801 key = "__all__"
2802 if key:
2803 if "duration" in pdat[key]:
2804 now = time.time()
2805 if now - start > pdat[key]["duration"]:
2806 return "run"
2807 if "kill" in pdat[key]:
2808 return "kill"
2809 else:
2810 return "run"
2811 time.sleep(1)
2812 except Exception as exc: # pylint: disable=broad-except
2813 log.error(
2814 "Failed to read in pause data for file located at: %s", pause_path
2815 )
2816 return "run"
2817 return "run"
2818
2819 def check_max_parallel(self) -> bool:
2820 """

Callers 1

call_chunksMethod · 0.95

Calls 4

timeMethod · 0.80
readMethod · 0.45
sleepMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected