-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch-framework.py
More file actions
45 lines (36 loc) · 1.32 KB
/
batch-framework.py
File metadata and controls
45 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import logging
import time
class BatchFramework:
def __init__(self, input_dir, output_dir, log_file):
self.input_dir = input_dir
self.output_dir = output_dir
self.log_file = log_file
def setup(self):
self.setup_logging()
self.create_output_directory()
def setup_logging(self):
logging.basicConfig(filename=self.log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def create_output_directory(self):
if not os.path.exists(self.output_dir):
os.makedirs(self.output_dir)
def process(self):
raise NotImplementedError("Subclasses must implement the 'process' method.")
def run(self):
try:
self.setup()
self.process()
except Exception as e:
logging.error(f"An error occurred: {str(e)}")
if __name__ == "__main__":
input_directory = "input_data"
output_directory = "output_data"
log_file = "batch.log"
class MyBatchProcess(BatchFramework):
def process(self):
logging.info("Batch process started.")
# Your batch processing logic goes here.
time.sleep(5)
logging.info("Batch process completed.")
batch = MyBatchProcess(input_directory, output_directory, log_file)
batch.run()