@@ -48,8 +48,8 @@ emergency_cleanup() {
4848 xcrun simctl shutdown " $SIMULATOR_UUID_TO_CLEAN " 2> /dev/null || true
4949 fi
5050
51- # Clean up push monitor specifically (don't kill all background jobs)
52- cleanup_push_monitoring
51+ # Clean up any background processes
52+ jobs -p | xargs -r kill 2> /dev/null || true
5353
5454 echo_warning " Emergency cleanup completed. Exiting with code $exit_code "
5555 exit $exit_code
@@ -349,14 +349,14 @@ prepare_test_environment() {
349349 if [[ -n " $CI " ]] || [[ -n " $GITHUB_ACTIONS " ]] || [[ -n " $JENKINS_URL " ]] || [[ -n " $BUILDKITE " ]]; then
350350 export CI=" 1"
351351 echo_info " 🤖 CI Environment detected - enabling mock push notifications"
352+ # Update config.json with CI mode only when CI is detected
353+ update_config_for_ci
352354 else
353355 export CI=" 0"
354356 echo_info " 📱 Local Environment - using real APNS push notifications"
357+ # Don't override existing config for local runs
355358 fi
356359
357- # Always update config.json to match detected environment
358- update_config_for_ci
359-
360360 if [[ " $VERBOSE " == true ]]; then
361361 export ENABLE_DEBUG_LOGGING=" 1"
362362 fi
@@ -476,43 +476,15 @@ setup_push_monitoring() {
476476 local PUSH_QUEUE_DIR=" /tmp/push_queue"
477477 mkdir -p " $PUSH_QUEUE_DIR "
478478
479- # Create log file for push monitor
480- local PUSH_MONITOR_LOG=" $LOGS_DIR /push_monitor.log"
481-
482479 echo_info " 📁 Push queue directory: $PUSH_QUEUE_DIR "
483- echo_info " 📝 Push monitor log: $PUSH_MONITOR_LOG "
484480 echo_info " 🔍 Starting background push monitor..."
485481
486- # Start background push monitor with logging
487- start_push_monitor " $PUSH_QUEUE_DIR " > " $PUSH_MONITOR_LOG " 2>&1 &
482+ # Start background push monitor
483+ start_push_monitor " $PUSH_QUEUE_DIR " &
488484 local MONITOR_PID=$!
489485 echo " $MONITOR_PID " > " /tmp/push_monitor.pid"
490486
491- # Give it a moment to start
492- sleep 1
493-
494- # Verify it's running
495- if ps -p " $MONITOR_PID " > /dev/null 2>&1 ; then
496- echo_info " ⚡ Push monitor started with PID: $MONITOR_PID "
497-
498- # Verify it's actually watching the directory
499- sleep 0.5
500- if [[ -f " $PUSH_MONITOR_LOG " ]]; then
501- if grep -q " Push monitor started" " $PUSH_MONITOR_LOG " 2> /dev/null; then
502- echo_info " ✓ Push monitor is actively watching for commands"
503- else
504- echo_warning " ⚠️ Push monitor log exists but may not be working correctly"
505- cat " $PUSH_MONITOR_LOG "
506- fi
507- fi
508- else
509- echo_error " ❌ Push monitor failed to start!"
510- if [[ -f " $PUSH_MONITOR_LOG " ]]; then
511- echo_error " Push monitor log:"
512- cat " $PUSH_MONITOR_LOG "
513- fi
514- echo_error " Push monitoring will not work!"
515- fi
487+ echo_info " ⚡ Push monitor started with PID: $MONITOR_PID "
516488 else
517489 echo_info " 📱 Local environment - push monitoring not needed"
518490 fi
@@ -521,47 +493,35 @@ setup_push_monitoring() {
521493start_push_monitor () {
522494 local PUSH_QUEUE_DIR=" $1 "
523495
524- # Use plain echo since this runs in background process
525- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 🔄 Push monitor started - watching: $PUSH_QUEUE_DIR " >&2
526- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 🔄 Monitor PID: $$ " >&2
527-
528- # Verify directory exists and is writable
529- if [[ ! -d " $PUSH_QUEUE_DIR " ]]; then
530- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ❌ ERROR: Push queue directory does not exist: $PUSH_QUEUE_DIR " >&2
531- exit 1
532- fi
533-
534- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ✓ Directory verified: $PUSH_QUEUE_DIR " >&2
496+ echo_info " 🔄 Push monitor started - watching: $PUSH_QUEUE_DIR "
535497
536498 while true ; do
537499 # Look for new command files
538500 for COMMAND_FILE in " $PUSH_QUEUE_DIR " /command_* .txt; do
539- # Skip if no files match the pattern
540- [[ -e " $COMMAND_FILE " ]] || continue
541501 [[ -f " $COMMAND_FILE " ]] || continue
542502
543- echo " [ $( date ' +%Y-%m-%d %H:%M:%S ' ) ] 📋 Found command file: $COMMAND_FILE " >&2
503+ echo_info " 📋 Found command file: $COMMAND_FILE "
544504
545505 # Read and execute the command
546506 local COMMAND=$( cat " $COMMAND_FILE " 2> /dev/null)
547507 if [[ -n " $COMMAND " ]]; then
548- echo " [ $( date ' +%Y-%m-%d %H:%M:%S ' ) ] 🚀 Executing push command: $COMMAND " >&2
508+ echo_info " 🚀 Executing push command: $COMMAND "
549509
550510 # Execute the xcrun simctl command
551- eval " $COMMAND " 2>&1
511+ eval " $COMMAND "
552512 local EXIT_CODE=$?
553513
554514 if [[ $EXIT_CODE -eq 0 ]]; then
555- echo " [ $( date ' +%Y-%m-%d %H:%M:%S ' ) ] ✅ Push notification sent successfully" >&2
515+ echo_info " ✅ Push notification sent successfully"
556516 else
557- echo " [ $( date ' +%Y-%m-%d %H:%M:%S ' ) ] ❌ Push notification failed with exit code: $EXIT_CODE " >&2
517+ echo_error " ❌ Push notification failed with exit code: $EXIT_CODE "
558518 fi
559519
560520 # Remove the command file after processing
561521 rm -f " $COMMAND_FILE "
562- echo " [ $( date ' +%Y-%m-%d %H:%M:%S ' ) ] 🗑️ Cleaned up command file: $COMMAND_FILE " >&2
522+ echo_info " 🗑️ Cleaned up command file: $COMMAND_FILE "
563523 else
564- echo " [ $( date ' +%Y-%m-%d %H:%M:%S ' ) ] ⚠️ Empty command file: $COMMAND_FILE " >&2
524+ echo_warning " ⚠️ Empty command file: $COMMAND_FILE "
565525 rm -f " $COMMAND_FILE "
566526 fi
567527 done
@@ -576,31 +536,6 @@ cleanup_push_monitoring() {
576536 local MONITOR_PID=$( cat /tmp/push_monitor.pid)
577537 echo_info " 🛑 Stopping push monitor (PID: $MONITOR_PID )"
578538
579- # Check if monitor is still running
580- if ps -p " $MONITOR_PID " > /dev/null 2>&1 ; then
581- echo_info " ✓ Push monitor is still running"
582- else
583- echo_warning " ⚠️ Push monitor process not found - may have crashed!"
584- fi
585-
586- # Show push monitor logs if they exist
587- local PUSH_MONITOR_LOG=" $LOGS_DIR /push_monitor.log"
588- if [[ -f " $PUSH_MONITOR_LOG " ]]; then
589- echo_info " 📋 Push monitor activity:"
590- cat " $PUSH_MONITOR_LOG "
591- else
592- echo_warning " ⚠️ Push monitor log not found: $PUSH_MONITOR_LOG "
593- fi
594-
595- # Check for unprocessed files in the queue
596- if [[ -d " /tmp/push_queue" ]]; then
597- local UNPROCESSED_COUNT=$( find /tmp/push_queue -type f | wc -l | tr -d ' ' )
598- if [[ $UNPROCESSED_COUNT -gt 0 ]]; then
599- echo_warning " ⚠️ Found $UNPROCESSED_COUNT unprocessed files in push queue:"
600- ls -la /tmp/push_queue/
601- fi
602- fi
603-
604539 kill " $MONITOR_PID " 2> /dev/null || true
605540 rm -f " /tmp/push_monitor.pid"
606541
0 commit comments