B
B
beginer1232016-08-14 09:20:32
PHP
beginer123, 2016-08-14 09:20:32

CRON how best to do?

Hello, I have a question.
The logic of the site is based on the fact that once a day I need to run some code.
Naturally through cron
So, what if suddenly my script suddenly falls?
I just launched it locally, it was interrupted, a minute later, without changing anything, I launched it again, it worked.
Let's take the simplest example, let's say the script should add +1 to a certain column for each record (there are a million of them)
. And for example, it broke on the 100,000th line
.
But not just anew, but taking into account his previous work.
How best to do this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Kitaev, 2016-08-14
@deliro

Store the state of the last run somewhere and check on every run.

L
lega, 2016-08-14
@lega

1. Make atomicity, transactions, if they are not, then in other ways, for example, if this is a file, then make the resulting file nearby and if everything is ok, then replace (rename) the original one.
2. Mark processed lines, in the line itself or from the outside.
3. Mark the current line inside/or outside if the process has a "strict" sequence.
Specifically, this task is not solved in this way, rows can not be updated at all:
1) you can calculate the value from the date the row was created
2) you can do +1 for just one value, and only the shift will be stored in all rows

Z
Zakhar Storozhuk, 2016-08-14
@Phell

On the last line of code - write some value to the file, write a second script that checks the value and if it is not there - run the script again.
That is, the first cron is at 12:00, the second at 12:05, the one at 12:05 is a script that checks the execution of the first script.
I think even if it didn’t turn on from the first, then your first script will start from the second time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question