latest_mmt_version
This commit is contained in:
108
MMT_latest_version/job_schedule/run_schedule.sh
Normal file
108
MMT_latest_version/job_schedule/run_schedule.sh
Normal file
@@ -0,0 +1,108 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
#!/bin/bash -e
|
||||
HOME="/home/compegence/customer"
|
||||
#Directories
|
||||
homeDir=$HOME/MMT
|
||||
configDir=$homeDir/conf
|
||||
input_file=$configDir/etl-config.txt
|
||||
declare -A credentials
|
||||
while IFS="=" read -r key value; do
|
||||
credentials[$key]=$value
|
||||
done < <( sed -e '/^\s*$/ d' -e '/^#/ d' $input_file )
|
||||
for i in ${credentials[@]}; do echo ***$i; done
|
||||
|
||||
user=${credentials[user]}
|
||||
password=${credentials[password]}
|
||||
host=${credentials[host]}
|
||||
db=${credentials[db]}
|
||||
protocol=${credentials[protocol]}
|
||||
server=${credentials[server]}
|
||||
db="mmt_intv1"
|
||||
|
||||
|
||||
#mmt_con="psql -X -A -t postgresql://$user:$password@$host/$db?options=--search_path%3D"
|
||||
|
||||
#dbname="mmt_tdm"
|
||||
#port=5432
|
||||
|
||||
psql_base_arg="postgresql://$user:$password@$host/$db"
|
||||
|
||||
echo $psql_base_arg
|
||||
|
||||
echo "Initiating a job"
|
||||
date
|
||||
|
||||
|
||||
|
||||
# load the record into the fw_jobctl_runschedule accounting for run frequency (hourly, daily, monthly, yearly) and insert
|
||||
## ???? Should this go into the first loop; to load only one runschedule
|
||||
/home/compegence/customer/MMT/job_schedule/job_load.sh
|
||||
|
||||
##***** Run frequency loop; Outer Loop
|
||||
## ???? Should we change it to select runschedules applicable, from the fw_jobctl_jobstep_master; and based on that run the loop
|
||||
#while loop for each client_id,function_id,run_frequency from fw_jobctl_runschedule_jobstep
|
||||
|
||||
while IFS="|" read -a outer
|
||||
do
|
||||
client_id=${outer[0]}
|
||||
function_id=${outer[1]}
|
||||
run_frequency=${outer[2]}
|
||||
|
||||
#Update start_time for fw_jobctl_runschedule
|
||||
|
||||
psql $psql_base_arg -c "update fw_core.fw_jobctl_runschedule set start_time=now(),begin_status='started' where client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and end_status is null "
|
||||
|
||||
##** Job and Step Loop; innner loop;
|
||||
#while loop for each job & step
|
||||
##** Job and Step Loop; innner loop; based on the entries on the table fw_jobctl_runschedule_jobstep
|
||||
while IFS="|" read -a inner
|
||||
do
|
||||
job_name=${inner[4]}
|
||||
step_name+=(${inner[5]})
|
||||
job_script_type=${inner[6]}
|
||||
job_step_script_name=${inner[7]}
|
||||
echo "$job_step_script_name"
|
||||
#remove first and last char - curly braces
|
||||
job_fun_param_array=${inner[8]:1:-1}
|
||||
#data_from_date=${inner[10]}
|
||||
#data_to_date=${inner[11]}
|
||||
#job_scope=${inner[12]}
|
||||
#job_scope_qualifier=${inner[13]}
|
||||
#echo $data_from_date,$data_to_date,$job_scope,$job_scope_qualifier
|
||||
param=''
|
||||
var1=' '
|
||||
echo "$job_fun_param"
|
||||
#reading array column and spliting each var and appending $ & space
|
||||
IFS=',' read -r -a ADDR <<< "$job_fun_param"
|
||||
for i in "${ADDR[@]}"; do
|
||||
echo $i
|
||||
param=$param$i$var1
|
||||
done
|
||||
|
||||
echo $param
|
||||
## Process java Program
|
||||
|
||||
if [ $job_script_type == "java" ] ; then
|
||||
|
||||
echo " $job_step_script_name started"
|
||||
|
||||
psql $psql_base_arg -c "update fw_core.fw_jobctl_runschedule_jobstep set start_time=now(),begin_status='started' where job_step_script_name='$job_step_script_name' and client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and latest_runschedule_flag='1' and job_script_type='java'"
|
||||
|
||||
# java -jar /home/compegence/mmt_code/generic_table/target/ex1-1.0-SNAPSHOT-shaded.jar
|
||||
java -jar $job_step_script_name
|
||||
psql $psql_base_arg -c "update fw_core.fw_jobctl_runschedule_jobstep set end_time=now(),end_status='success',end_status_note='stg1_completed', latest_runschedule_flag='0' where job_step_script_name='$job_step_script_name' and client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and latest_runschedule_flag='1' and job_script_type='java'"
|
||||
|
||||
echo " $job_step_script_name Ended"
|
||||
fi
|
||||
## End of While Loop
|
||||
#2nd looping through fw_core.fw_jobctl_runschedule_jobstep for each client_id,function_id,run_frequency,run_schedule_id1 is completed
|
||||
done < <(psql $psql_base_arg -At -c"select client_id,function_id,run_frequency,run_schedule_id,job_name,step_name,job_script_type,job_step_script_name,job_fun_param_array,job_step_run_dependency_seuqence from fw_core.fw_jobctl_runschedule_jobstep where latest_runschedule_flag='1' and client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' order by run_schedule_id,job_step_run_dependency_seuqence; ")
|
||||
|
||||
|
||||
#Update end_time for fw_jobctl_runschedule
|
||||
psql $psql_base_arg -c "update fw_core.fw_jobctl_runschedule set latest_runschedule_flag='0',end_time=now(),end_status='success',end_status_note='stg1_completed' where client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and latest_runschedule_flag='1' and end_status is null "
|
||||
#1st loop for client_id,function_id,run_frequency
|
||||
done < <(psql $psql_base_arg -At -c"select distinct client_id,function_id,run_frequency from fw_core.fw_jobctl_runschedule_jobstep where latest_runschedule_flag='1' order by client_id,function_id,run_frequency ")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user