Calculate total running time and pause time - sql

Calculate total running time and pause time
I have table as shown in attached image.
Transaction Status meaning : 3= start, 6= pause, 5=stop
I need running time & pause time for batch run template id
Notes :
Transaction can be paused and resumed multiple times as shown in image
STOP can occure only once and can occur after the pause transaction or start transaction
if a transaction started but not paused and stopped system should pick up the current date to calculate

Here is my answer to very same problem. Please check this, and slightly modify by your needs :)

Related

Pandas Date Time

This is the data recording reported by sensor and its being updated in every 20mins
Sensor Reading
In this case, I would like to find out the outage time period. Anyone can suggest on how to find the outage time. Like in the picture shown above that the down time occurs at 40 minutes long.

Capture the time taken by the jobstream to complete

Could someone help me with the command to find the start time and end time of a jobstream.
I am aware that the jobs have this info, but I am looking out for time taken by jobstream.

Background Threads in Horizontally Scaled Application

The current situation is that I have an application that scales horizontally with one SQL database. Periodically, a background process is ran but I only want one invocation of this background process running at a time. I have tried to accomplish this by using a database row and locking but I am stuck. The requirement is that only one batch job should have successfully completed per day.
Currently I have a table called lock which has three columns: timestamp, lock_id, status. Status is an enum that has three values 0 = not running, 1 = running, 2 = completed.
The issue is that if a batch job fails and status is equal to 0, How can I make sure that only one background process will retry. How do I guarantee that only one background process is running in the retry scenario?
In an ideal world, I would like to do a SELECT statement that checks for the STATUS in the locking table, if status is = 0 meaning not running then start the background job and change status to 1 = running. However, if all horizontally scaled processes do this at the same time, is it guaranteed that only one is executed?
Thanks!

How to alert on an event that normally happens once a day?

I have a batch job that runs once per day.
At the end of the job I submit a meter metric with a count of the items processed.
I want to alert if one day this metric is not updated.
On http://metrics.librato.com the maximum time I can check "not reported for" when creating an alert is 60 minutes.
I thought maybe I can create a composite metric and take the avg rate of change over the past 24 hours, and alert if that reaches zero.
I've been trying:
derive(s("my.metric", "%", {function:"sum", period:"86400"}))
However it seems that, because I log only a single event, above quite small values of period (~250s) my rate of change simply drops to zero ...I guess the low frequency means my single value is completely lost by the sampling.
Maybe I am using the wrong tool for the job...
Is there a way to achieve this in Librato?
There currently is not a way to achieve this as composite metrics are subject to the 60 minute limitation of alerts as well (as of 5/15/2015). You may need to look into configuring the metric (or a similar metric) to report within the 60m time range if possible.

Different delay tipe for the same process Arena

I need to change the delay type of a process during the simulation in Arena. For example I need a delay type costant for the first two hours and then a triangular delay for 3 hours.
You can try putting a decide just before the process. In that decide you can give conditions about the time decision. For instance, if the current time is at 2 hours, its exit point will go to an assign module that will assign its process time to a wanted constant. Or if it is 3 hours then it will go to another assign that will assign the process time of that current entity to a triangular distribution.
After that you can connect all these assigns to the "process" module and enter the delay type as an expression which will be the attribute you choose to assign the process times.