Sunday 20 September 2015

To get all workflows which have scheduled time in the next half an hour and started 15 mins back and are running

Use Case:

1.We want to postpone the backup n the basis of count of running workflows around the backup time

Solution:



# Define a timestamp function
timestamp() {
  #date +"%T"
  date +"%s%3N"
}
var=`timestamp`
var1=$(expr $var + 1800000)
var2=$(date +"%Y-%m-%d"T"%T" --date='15 minutes ago')
var3=${var2}.000Z
# To get all workflows which have scheduled time in the next half an hour
curl -s -g -u admin:admin 'http://localhost:40102/crx/de/query.jsp?_dc=1418076406834&_charset_=utf-8&type=xpath&stmt=/jcr:root/etc/workflow/instances//*[(@absoluteTime>="'$var'")and(@absoluteTime<="'$var1'")]&showResults=true' |sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\;/g' | sed 's/[\,]/ /g' | sed 's/\"//g' |sed 's/results\:\[//g' |sed 's/\/metaData//g'|sed 's/\/data//g' |grep path>/tmp/count
sleep 1
# To get all the workflows which is started 15 mins back and are running
curl -s -g -u admin:admin 'http://localhost:40102/crx/de/query.jsp?_dc=1418076406834&_charset_=utf-8&type=xpath&stmt=/jcr:root/etc/workflow/instances//*[(@startTime>=xs:dateTime("'$var3'"))and@modelId!="/etc/workflow/models/scheduled_activation"and@modelId!="/etc/workflow/models/scheduled_deactivation"and@status!="ABORTED"and@status!="COMPLETED"]&showResults=true' |sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\;/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | sed 's/results\:\[//g' |grep path>>/tmp/count
sleep 1

No comments:

Post a Comment