logging fix
This commit is contained in:
parent
c27e4dff80
commit
afe33ef381
|
|
@ -139,22 +139,31 @@ sqs = boto3.client('sqs', region_name=config.aws_region)
|
||||||
s3 = boto3.client('s3', region_name=config.aws_region)
|
s3 = boto3.client('s3', region_name=config.aws_region)
|
||||||
ses = boto3.client('ses', region_name=config.aws_region)
|
ses = boto3.client('ses', region_name=config.aws_region)
|
||||||
|
|
||||||
# DynamoDB
|
# DynamoDB - initialized lazily
|
||||||
dynamodb = boto3.resource('dynamodb', region_name=config.aws_region)
|
dynamodb = boto3.resource('dynamodb', region_name=config.aws_region)
|
||||||
DYNAMODB_AVAILABLE = False
|
DYNAMODB_AVAILABLE = False
|
||||||
rules_table = None
|
rules_table = None
|
||||||
messages_table = None
|
messages_table = None
|
||||||
|
_dynamodb_initialized = False
|
||||||
|
|
||||||
try:
|
def init_dynamodb():
|
||||||
rules_table = dynamodb.Table(config.rules_table)
|
"""Initialize DynamoDB tables (called once from main)"""
|
||||||
messages_table = dynamodb.Table(config.messages_table)
|
global DYNAMODB_AVAILABLE, rules_table, messages_table, _dynamodb_initialized
|
||||||
# Test connection
|
|
||||||
rules_table.table_status
|
if _dynamodb_initialized:
|
||||||
messages_table.table_status
|
return
|
||||||
DYNAMODB_AVAILABLE = True
|
_dynamodb_initialized = True
|
||||||
log(f"DynamoDB connected: {config.rules_table}, {config.messages_table}")
|
|
||||||
except Exception as e:
|
try:
|
||||||
log(f"Warning: DynamoDB not available: {e}", 'WARNING')
|
rules_table = dynamodb.Table(config.rules_table)
|
||||||
|
messages_table = dynamodb.Table(config.messages_table)
|
||||||
|
# Test connection
|
||||||
|
rules_table.table_status
|
||||||
|
messages_table.table_status
|
||||||
|
DYNAMODB_AVAILABLE = True
|
||||||
|
log(f"DynamoDB connected: {config.rules_table}, {config.messages_table}")
|
||||||
|
except Exception as e:
|
||||||
|
log(f"Warning: DynamoDB not available: {e}", 'WARNING')
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# SMTP CONNECTION POOL
|
# SMTP CONNECTION POOL
|
||||||
|
|
@ -1268,15 +1277,20 @@ def start_health_server(worker: UnifiedWorker):
|
||||||
# ENTRY POINT
|
# ENTRY POINT
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
||||||
# Global flag to prevent double execution
|
|
||||||
_worker_started = False
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global _worker_started
|
# Use a lock file to prevent double execution
|
||||||
if _worker_started:
|
import fcntl
|
||||||
log("⚠ Worker already started, ignoring duplicate call", 'WARNING')
|
lock_file = '/tmp/unified_worker.lock'
|
||||||
return
|
|
||||||
_worker_started = True
|
try:
|
||||||
|
lock_fd = open(lock_file, 'w')
|
||||||
|
fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
|
except (IOError, OSError):
|
||||||
|
print("Another instance is already running, exiting.", flush=True)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Initialize DynamoDB (only once)
|
||||||
|
init_dynamodb()
|
||||||
|
|
||||||
worker = UnifiedWorker()
|
worker = UnifiedWorker()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue