-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from touero/develop
Implemented customized deletion of containers
- Loading branch information
Showing
17 changed files
with
156 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,8 @@ container: | |
network: | ||
name: bridge | ||
driver: bridge | ||
|
||
extra: | ||
'is_remove': 1 | ||
'days_ago_remove': 7 | ||
'remove_now': 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
from .log_re import log | ||
from .config import Config | ||
|
||
__version__ = '2.2.5' | ||
__version__ = '2.2.6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
class ContainerStatus(IntEnum): | ||
RUNNING = 1 # running | ||
EXITED = 2 # exited | ||
CREATED = 3 # created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
import time | ||
|
||
from datetime import datetime | ||
|
||
from docker.models.containers import Container | ||
from .log_re import log | ||
from .constants import ContainerStatus | ||
|
||
|
||
def check_container(container: Container) -> ContainerStatus: | ||
for _ in range(60): | ||
def check_container_status(container: Container) -> ContainerStatus: | ||
for index in range(60): | ||
time.sleep(1) | ||
if container.status != ContainerStatus.RUNNING.name.lower(): | ||
if container.status == ContainerStatus.CREATED.name.lower(): | ||
continue | ||
if container.status != ContainerStatus.RUNNING.name.lower() and index == 0: | ||
container.reload() | ||
continue | ||
elif container.status == ContainerStatus.RUNNING.name.lower(): | ||
return ContainerStatus.RUNNING | ||
elif container.status == ContainerStatus.EXITED.name.lower(): | ||
log(f'Container name: [{container.name}] is exited') | ||
return ContainerStatus.EXITED | ||
|
||
|
||
def check_time(target_time_str, days_ago_remove): | ||
""" | ||
Check if the target_time_str is within the last days_ago_remove days | ||
:param target_time_str: timestamp in ISO 8601 format, accurate to nanoseconds. | ||
:param days_ago_remove: how many days old will the container be forcibly removed | ||
:return: | ||
""" | ||
target_time_str = target_time_str[:26] + 'Z' | ||
target_time = datetime.strptime(target_time_str, "%Y-%m-%dT%H:%M:%S.%fZ") | ||
current_time = datetime.utcnow() | ||
time_diff = current_time - target_time | ||
if time_diff.days >= days_ago_remove: | ||
return True | ||
return False |
Oops, something went wrong.