forked from Alexey/DAS_2024_1
что-то есть
This commit is contained in:
parent
6b55b7b0fc
commit
2b87427299
2
tsukanova_irina_lab_2/.gitignore
vendored
Normal file
2
tsukanova_irina_lab_2/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/.venv
|
||||
/.idea
|
17
tsukanova_irina_lab_2/docker-compose.yaml
Normal file
17
tsukanova_irina_lab_2/docker-compose.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
services:
|
||||
worker_one:
|
||||
container_name: worker_one
|
||||
build:
|
||||
context: ./worker-1
|
||||
volumes:
|
||||
- ./data:/var/data
|
||||
- ./result:/var/result
|
||||
|
||||
worker_two:
|
||||
container_name: worker_two
|
||||
build:
|
||||
context: ./worker-2
|
||||
depends_on:
|
||||
- worker_one
|
||||
volumes:
|
||||
- ./result:/var/result
|
1
tsukanova_irina_lab_2/result/data.txt
Normal file
1
tsukanova_irina_lab_2/result/data.txt
Normal file
@ -0,0 +1 @@
|
||||
5 34 7 9 6 43 5 768 4 23 1 3 657 534 4 3 87 6 9 8 56 37 525 5 7 3 2 65 4 86 7 295 473 254 633 4 45 2
|
11
tsukanova_irina_lab_2/worker-1/Dockerfile
Normal file
11
tsukanova_irina_lab_2/worker-1/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
# Использую базовый образ Python
|
||||
FROM python:3.12-slim
|
||||
|
||||
# Устанавливаю рабочую директорию внутри контейнера
|
||||
WORKDIR /app
|
||||
|
||||
# Копирую все файлы в контейнер
|
||||
COPY worker_1.py .
|
||||
|
||||
# Команда для запуска Python-скрипта
|
||||
CMD ["python", "worker_1.py"]
|
27
tsukanova_irina_lab_2/worker-1/worker_1.py
Normal file
27
tsukanova_irina_lab_2/worker-1/worker_1.py
Normal file
@ -0,0 +1,27 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
# Ищет в каталоге /var/data самый большой по объёму файл и перекладывает его в /var/result/data.txt.
|
||||
print("start one")
|
||||
dir_data = "/var/data"
|
||||
dir_res = "/var/result"
|
||||
|
||||
if not os.path.exists(dir_data):
|
||||
os.mkdir(dir_data)
|
||||
|
||||
if not os.path.exists(dir_res):
|
||||
os.mkdir(dir_res)
|
||||
|
||||
largest_file = None
|
||||
largest_size = 0
|
||||
|
||||
for root, dirs, files in os.walk(dir_data):
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
file_size = os.path.getsize(file_path)
|
||||
if file_size > largest_size:
|
||||
largest_size = file_size
|
||||
largest_file = file_path
|
||||
|
||||
if largest_file:
|
||||
shutil.copyfile(largest_file, dir_res + "/data.txt")
|
11
tsukanova_irina_lab_2/worker-2/Dockerfile
Normal file
11
tsukanova_irina_lab_2/worker-2/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
# Использую базовый образ Python
|
||||
FROM python:3.12-slim
|
||||
|
||||
# Устанавливаю рабочую директорию внутри контейнера
|
||||
WORKDIR /app
|
||||
|
||||
# Копирую все файлы в контейнер
|
||||
COPY worker_2.py .
|
||||
|
||||
# Команда для запуска Python-скрипта
|
||||
CMD ["python", "worker_2.py"]
|
19
tsukanova_irina_lab_2/worker-2/worker_2.py
Normal file
19
tsukanova_irina_lab_2/worker-2/worker_2.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Сохраняет произведение первого и последнего числа из файла /var/result/data.txt в /var/result/result.txt.
|
||||
|
||||
print("start two")
|
||||
|
||||
with open('/var/result/data.txt', 'r') as f:
|
||||
numbers = [int(num) for num in f.read().split() if num.isdigit()]
|
||||
|
||||
if numbers:
|
||||
first_number = numbers[0]
|
||||
last_number = numbers[-1]
|
||||
|
||||
result = first_number * last_number
|
||||
|
||||
with open('/var/result/result.txt', 'w') as f:
|
||||
f.write(f"{result}\n")
|
||||
|
||||
print(f"Получен результат - {result}")
|
||||
else:
|
||||
print("Результат не получен. Файл не содержит чисел")
|
Loading…
Reference in New Issue
Block a user