logging fix
This commit is contained in:
parent
c27e4dff80
commit
afe33ef381
|
|
@ -139,11 +139,20 @@ sqs = boto3.client('sqs', region_name=config.aws_region)
|
|||
s3 = boto3.client('s3', 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_AVAILABLE = False
|
||||
rules_table = None
|
||||
messages_table = None
|
||||
_dynamodb_initialized = False
|
||||
|
||||
def init_dynamodb():
|
||||
"""Initialize DynamoDB tables (called once from main)"""
|
||||
global DYNAMODB_AVAILABLE, rules_table, messages_table, _dynamodb_initialized
|
||||
|
||||
if _dynamodb_initialized:
|
||||
return
|
||||
_dynamodb_initialized = True
|
||||
|
||||
try:
|
||||
rules_table = dynamodb.Table(config.rules_table)
|
||||
|
|
@ -1268,15 +1277,20 @@ def start_health_server(worker: UnifiedWorker):
|
|||
# ENTRY POINT
|
||||
# ============================================
|
||||
|
||||
# Global flag to prevent double execution
|
||||
_worker_started = False
|
||||
|
||||
def main():
|
||||
global _worker_started
|
||||
if _worker_started:
|
||||
log("⚠ Worker already started, ignoring duplicate call", 'WARNING')
|
||||
return
|
||||
_worker_started = True
|
||||
# Use a lock file to prevent double execution
|
||||
import fcntl
|
||||
lock_file = '/tmp/unified_worker.lock'
|
||||
|
||||
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()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue