M
Marc Hoeppner
Hi!
I have been using Ruby for a while now - so I have a reasonable
understanding of how it works.
But I have a problem that I can't seem to be able to solve on my own, so
here goes:
I am using an active records based script that queries a remote MySQL
database and retrieves data. It's quite an extensive search, meaning it
takes a long time to run. Unfortunately, the connection closes at random
(I suppose there is some sort of time-out if a connection has been
existing for a certain amount of time).
I have the means of identifying the current ID of the last object and
pick up the search where it left off - manually. And that's the problem:
How to write a wrapper or some loop that:
a) Detects if the database connections closes
b) keeps track of the id of the last processed database object (I
suppose that can be stored in a variable, if we are talking about a
loop, otherwise a "return id"like command (?)
c) re-initializes the script using the last id
I am thinking either a second script, that starts the original
database-search-script and can keep track of its current status or else
a while-loop perhaps?
Since the script simply aborts when the connection closes, I suppose the
first solution would be better?
But I have no idea how to:
- keep track of the "health" of the original process (there is obviously
an error message returned to STDOUT, but I am not sure how to pick it
up)
- start a ruby script from within a ruby script
- or else how to write a loop that keeps track of the child process
without the whole process being terminated by an error
Any help would be greatly appreciated!
Cheers,
Marc
I have been using Ruby for a while now - so I have a reasonable
understanding of how it works.
But I have a problem that I can't seem to be able to solve on my own, so
here goes:
I am using an active records based script that queries a remote MySQL
database and retrieves data. It's quite an extensive search, meaning it
takes a long time to run. Unfortunately, the connection closes at random
(I suppose there is some sort of time-out if a connection has been
existing for a certain amount of time).
I have the means of identifying the current ID of the last object and
pick up the search where it left off - manually. And that's the problem:
How to write a wrapper or some loop that:
a) Detects if the database connections closes
b) keeps track of the id of the last processed database object (I
suppose that can be stored in a variable, if we are talking about a
loop, otherwise a "return id"like command (?)
c) re-initializes the script using the last id
I am thinking either a second script, that starts the original
database-search-script and can keep track of its current status or else
a while-loop perhaps?
Since the script simply aborts when the connection closes, I suppose the
first solution would be better?
But I have no idea how to:
- keep track of the "health" of the original process (there is obviously
an error message returned to STDOUT, but I am not sure how to pick it
up)
- start a ruby script from within a ruby script
- or else how to write a loop that keeps track of the child process
without the whole process being terminated by an error
Any help would be greatly appreciated!
Cheers,
Marc