Checking for the status of a job on the webserver R - r

I am executing the getURL command to check the status of a task on the server using this function below.
getURL(content(t2)$statusURL)
The status could be either "Processing" when the task is in process or "Completed_Successfully" when the task is completed.
Only if the task status is "Completed_Successfully" the following code below should be executed
getURL(content(t2)$ouptputURL)
If the task status is still in "Processing" the code should wait until it changes to "Completed_Successfully"
Need help writing this logic in R ?

I had a similar problem a few years ago. I decided to ask the Windows Task Manager (yes, I have sinned) to run a specific script on a regular basis. Your script could be along the lines of
isok <- FALSE
i <- 1
while (isok == FALSE) {
record.start <- Sys.time()
message("Checking if job done")
Sys.sleep(i)
record.end <- Sys.time()
see.difference <- record.end - record.start
message(paste("Waiting time:", round(see.difference)))
if (see.difference >= 5) {
isok <- TRUE
message("Job completed")
}
i <- i + 1
}
Checking if job done
Waiting time: 1
Checking if job done
Waiting time: 2
Checking if job done
Waiting time: 3
Checking if job done
Waiting time: 4
Checking if job done
Waiting time: 5
Job completed

Related

Is there a way to make a Denodo 8 VDP scheduler job WAIT() for a certain amount of time?

I want to make a VDP scheduler job in Denodo 8 wait for a certain amount of time. The wait function in the job creation process is not working as expected so I figured I'd write it into the VQL. However when i try the suggested function from the documentation (https://community.denodo.com/docs/html/browse/8.0/en/vdp/vql/stored_procedures/predefined_stored_procedures/wait) the Denodo 8 VQL shell doesn't recognize the function.
--Not working
SELECT WAIT('10000');
Returns the following error:
Function 'wait' with arity 1 not found
--Not working
WAIT('10000');
Returns the following error:
Error parsing command 'WAIT('10000')'
Any suggestions would be much appreciated.
There are two ways of invoking WAIT:
Option #1
-- Wait for one minute
CALL WAIT(60000);
Option #2:
-- Wait for ten seconds
SELECT timeinmillis
FROM WAIT()
WHERE timeinmillis = 10000;

Autosys job not to trigger twice during some period

My job A is dependent on the parent job B and A is triggered when B succeed.
The problem is that B may finish several times during the day by mistake (bug in upstream).
How could I make A depend on B and trigger only if it was not already triggered the same day?
Didn't found any other solution but introducing new 'defensive job' in the middle with:
command: (( "X$(date +%F)" != "X$(cat defensive_trigger_date)" )) && ( echo $(date +%F) > defensive_trigger_date; echo $(date +%F) )
High level logic:
If current system date is not equal to last job trigger date (from the file) flush current system date to the file and exit with zero exit code (succeed the job)
Else exit with non-zero exit code (fail the job)

Prompt user without waiting

I have a long running process, coded in "R". I would like to continue running it in RStudio, I don't want to use batch mode.
I would like to allow the user to gracefully terminate the long running process, for example by pressing the escape key. If the user doesn't press anything, the process continues, without waiting.
I have read other StackOverflow posts, perhaps I need to prompt the user using scan/readline on a different thread. That way, the main execution thread isn't blocked.
Isn't there a simpler way?
Thank you for any pointers/suggestions.
Richard Rogers
Further comments:
I've made a few mistakes:
I didn't realize that pressing escape in RStudio while the code is
running halts execution.
I can't seem to determine where execution ends when I press escape.
Maybe I can use a simpler question.
Here is a simple function:
ProcessData <- function()
{
Continue <- TRUE
Iteration <- 1
TestData <- vector(mode = "integer", length = 100000)
while (Continue)
{
writeLines(sprintf("Processing iteration %d, Current time is %s", Iteration, Sys.time()))
process.events()
TestData <- round(runif(100000, min = 1, max = 10))
# Continue <- PromptUser()
Iteration <- Iteration + 1
}
writeLines("Processing ending.")
head(TestData)
}
If I press escape while the loop is running, the writeLines and head calls don't get executed. How can I ensure that they do?
Thank you again,
Richard
I know this is an old question, but since I had a similar context (long-running task), here is what I came up with:
long_computation <- function() for(i in 1:10) Sys.sleep(1)
exit_gracefully <- function() cat("Saving results so far...\n")
tryCatch(
long_computation(),
finally = exit_gracefully()
)
If we press escape during the computation, no error condition seems to be thrown; however the finally part of tryCatch gets executed. This allows us to clean up, close connections etc.

How to determine the execution stop event of a program

I have a script which logs certain data when a benchmark (some c code like matrix multiplication) runs.
I want to first start the log script when benchmark starts, this is easy since I can just start the binary from the log script and then proceed to log the info.
But the real question is when do I stop it? The benchmark can stop at anytime (The log script shouldn't stop the benchmark). How do I get the info/variable which can be used in the log script to stop it when benchmark program stops?
I was thinking if I can use PID of the benchmark, but then thought there should be a better solution than searching and using the PID.
Thanks!
Perhaps you could try something like this:
#!/bin/bash
#
# Your main script
#
# Run your log program in background
your_log_program &
# The PID of last background program
LOGPROGRAMPID=$!
# Install EXIT trap (EXIT is a bash's special event)
trap 'kill -15 $LOGPROGRAMPID; exit 0' EXIT
# In foreground launch your benchmark program
run_your_benchmark_program
# When benchmark program ends your trap will be launched and it will kill your log
# program.

Counting a number of occurrences of a string between 2 strings in a text file with UNIX

I have been working on this for a little while and have been unable to come to a solution. Any help would be appreciated. I am working on a UNIX workstation and have a 30-40 meg text file that I am working with. In my real file there is hundreds of Jobs. Example of input file;
# misc logging data
Job 1 start
Task start
Task stop
Task start
Task stop
Job 1 stop
# Other misc logging data
Job 2 start
Task start
Task stop
Job 2 stop
# Other misc logging data
Job 3 start
Task start
Task stop
Task start
Task stop
Task start
Task stop
Job 3 stop
My desired output is:
Job 1, 2 Tasks
Job 2, 1 Tasks
Job 3, 3 Tasks
Thanks again...
awk '/^Job .* start$/ { jobname = $2; taskcount = 0; }
/^Task start/ { taskcount++; }
/^Job .* stop$/ { printf "Job %s, %d Tasks\n", jobname, taskcount; }'
This doesn't do a lot of checking (making sure the job ending is the job that was started; checking that each started task stopped, etc.), but it does process the data you provided and give the output you required.
If the 'Other misc logging data' lines could contain stuff confused with a given job and its tasks (could match the Task start line, etc), then you have to be a bit cleverer.

Resources