#!/bin/bash

crontabSetupTaskProcessor() 
{
  local task_processor_script="$install_scripts_dir/crontab/task/crontab_task_processor.sh"
  local task_dir="$containers_dir/libreportal/frontend/data/tasks"
  
  # Update TASK_DIR in the task processor script
  if [ -f "$task_processor_script" ]; then
    sed -i "s|TASK_DIR=\".*\"|TASK_DIR=\"$task_dir\"|g" "$task_processor_script"
    chmod +x $task_processor_script
  else
    isNotice "Task processor script not found"
  fi
  
  local cronEntry="* * * * * $task_processor_script start_script"
  
  # Check if already in crontab
  if runAsManager crontab -l 2>/dev/null | grep -q "crontab_task_processor.sh"; then
    isNotice "Task processor already in crontab"
  else
    # Add to crontab
    (runAsManager crontab -l 2>/dev/null; echo "$cronEntry") | runAsManager crontab -
    isSuccessful "Continuous task processor added to crontab."
  fi
}
