Project

General

Profile

Actions

Feature #4019

closed

Make events implement a method that returns whether they ran successfully

Added by Ingo Renner over 15 years ago. Updated almost 11 years ago.

Status:
Closed
Priority:
Should have
Assignee:
Category:
scheduler
Target version:
-
Start date:
2009-07-28
Due date:
% Done:

100%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

The scheduler currently logs to the Admin Tools->Log module when it strats execution of an event. However, it does not log when a task finished running and whether it ran successfully.

Thus it seems to be a good idea to require events to implement a method that returns whether the execution was successfull.
An abstract method in the event class should do IMO.


Files

4019.diff (7.03 KB) 4019.diff Ingo Renner, 2009-08-17 18:56
4019v2_exceptions.diff (12.5 KB) 4019v2_exceptions.diff Ingo Renner, 2009-08-18 16:58
Actions #1

Updated by Francois Suter over 15 years ago

That sounds reasonable indeed.

Actions #2

Updated by Ingo Renner over 15 years ago

  • Assignee set to Ingo Renner
Actions #3

Updated by Ingo Renner over 15 years ago

A separate method is not needed after all. It should be enough to evaluate the return value of a task's execute() method: True, everything's good; false, an error occured.

The attached patch simply does this and saves the result to the DB so that it can be shown in the task list.

Francois, I'm not sure whether we should really set the default value for $successfullyExecuted in tx_scheduler_Task::unmarkExecution() to false. On the one hand side we could argue that it's a new implementation (scheduler in core) and thus developers have to adopt to the API anyways. On the other hand side developers might not notice that they actually have to return a boolean value according to the execution status.

Actions #4

Updated by Francois Suter over 15 years ago

  • Status changed from New to Needs Feedback

A separate method is not needed after all. It should be enough to evaluate the return value of a task's execute() method: True, everything's good; false, an error occured.

I agree that no new method is needed, but see below...

The attached patch simply does this and saves the result to the DB so that it can be shown in the task list.

I was thinking about another solution: the execute() method of a given task could be allowed to throw exceptions (in case of fatal problems). So exception could be caught indicating a failure, rather than getting a boolean return value. The advantage is that the exception could return a message which would be better for information.

Instead of having a lastexecution_success field, we could call it lastexecution_message. It would be left empty if no exception was thrown and filled with the message otherwise. The message can then be read and displayed in the BE module. It could also be written to the sys_log, so that an admin can go back through the history. Or it could be mix and match: the BE module just displays a failure icon and instructs the admin to look at the sys_log. Or the message could come as a tooltip when moving over the icon, whatever.

I don't think it needs to be more detailed, as a developer can always add devlog calls in his task class if he needs to keep more details.

Francois, I'm not sure whether we should really set the default value for $successfullyExecuted in tx_scheduler_Task::unmarkExecution() to false. On the one hand side we could argue that it's a new implementation (scheduler in core) and thus developers have to adopt to the API anyways. On the other hand side developers might not notice that they actually have to return a boolean value according to the execution status.

I wouldn't worry about this too much. There are many changes anyway and I would include a chapter about adapting a Gabriel event to a Scheduler task in the manual.

Actions #5

Updated by Ingo Renner over 15 years ago

Francois Suter wrote:

I was thinking about another solution: the execute() method of a given task could be allowed to throw exceptions (in case of fatal problems). So exception could be caught indicating a failure, rather than getting a boolean return value. The advantage is that the exception could return a message which would be better for information.

Good idea, I thought about how to provide a message too, but rather through a separate method like mysql_errno() does. A exception would be a superior solution of course. I'd suggest to have it like now, with a boolean and add the exception handling on top for more detailed responses.

Instead of having a lastexecution_success field, we could call it lastexecution_message. It would be left empty if no exception was thrown and filled with the message otherwise. The message can then be read and displayed in the BE module.

using flash messages for example :)

It could also be written to the sys_log, so that an admin can go back through the history.

Sounds good too, as the current approach would take care of the very last failure only.

Or it could be mix and match: the BE module just displays a failure icon and instructs the admin to look at the sys_log. Or the message could come as a tooltip when moving over the icon, whatever.

Tooltip is also good in case multiple tasks fail so that it's easy to see which task failed for which reason.

I'll go ahead with the changes...

Francois, I'm not sure whether we should really set the default value for $successfullyExecuted in tx_scheduler_Task::unmarkExecution() to false. On the one hand side we could argue that it's a new implementation (scheduler in core) and thus developers have to adopt to the API anyways. On the other hand side developers might not notice that they actually have to return a boolean value according to the execution status.

I wouldn't worry about this too much. There are many changes anyway and I would include a chapter about adapting a Gabriel event to a Scheduler task in the manual.

great!

Actions #6

Updated by Ingo Renner over 15 years ago

Updated the patch to use a mix of booleans and exceptions. Boolean false gets converted into a general exception, true (= everything's good) is ignored.

Actions #7

Updated by Francois Suter over 15 years ago

The patch looks globally good, but I think there's a logic flaw with this part:

if (!$successfullyExecuted) {
    throw new tx_scheduler_FailedExecutionException(
        'Task failed to execute successfully. CRID: ' . $task->getCrid() . ', UID: ' . $task->getTaskUid(),
        1250596541
    );
}

As far as I can see the exception must not be thrown. It must be instantiated and stored into $failure, so that it can be passed to unmarkExecution(). Right?

Actions #8

Updated by Ingo Renner over 15 years ago

Francois Suter wrote:

As far as I can see the exception must not be thrown. It must be instantiated and stored into $failure, so that it can be passed to unmarkExecution(). Right?

Nope, it's correct the way it is, by throwing the exeption in the try block it's cought in the catch block below. Also if a task throws an exception while executing the execution of the task will stop at that point and will not reach the mentioned if so that the task's original exception is caught by the catch block.

:)

Actions #9

Updated by Francois Suter over 15 years ago

Nope, it's correct the way it is, by throwing the exeption in the try block it's cought in the catch block below.

I didn't expect this behaviour, but it's fine then. Go ahead and I'll do a post-commit review.

Actions #10

Updated by Ingo Renner over 15 years ago

  • Status changed from Needs Feedback to Resolved
  • % Done changed from 0 to 100

Applied in changeset r1124.

Actions #11

Updated by Francois Suter over 15 years ago

  • Status changed from Resolved to Needs Feedback

I've reviewed and tested your patch and I run into some problems in the BE module. I have to test further, but one thing is sure: when manually executing a task, the BE module also ends up tx_scheduler::executeTask() like the CLI dispatch script. The problem is that the BE module doesn't follow the same workflow and the error reporting is currently broken.

I'm reopening this issue, to be sure not to forget.

Actions #12

Updated by Francois Suter about 15 years ago

OK, I know what the problem is: in the BE module, every time a task has a non-empty "lastexecution_failure" field, the error message of that failure is displayed as an error box. This is not correct as it means the error is displayed all the time until the task has run again. This may not happen for a good while if the task runs at low intervals (say, once a day or less). During all this time, the error message will be displayed, which is totally confusing.

I propose to just put the error message as a hover of the failure bullet (as it is now) and not as an error message. We could add an indication in the legend, that people should hover over the failure bullet to get more details.

Actions #13

Updated by Francois Suter about 15 years ago

Just a note: after quite some reviewing of the scheduler code, I have a good idea of what could be streamlined in the execution process. This simplification in turn will make it easier to solve the different error reportings that are needed depending on the execution process (CLI script or BE module).

I just don't have the time to do it tonight. Stay tuned!

Actions #14

Updated by Ingo Renner about 15 years ago

Francois Suter wrote:

OK, I know what the problem is: in the BE module, every time a task has a non-empty "lastexecution_failure" field, the error message of that failure is displayed as an error box. This is not correct as it means the error is displayed all the time until the task has run again. This may not happen for a good while if the task runs at low intervals (say, once a day or less). During all this time, the error message will be displayed, which is totally confusing.

Well to me that's intended behavior. It's also what we agreed on AFAIR - to show the message until someone spots it and resolves the error (by fixing it and running the task again). How would I otherwise notice?

Actions #15

Updated by Francois Suter about 15 years ago

Well to me that's intended behavior. It's also what we agreed on AFAIR - to show the message until someone spots it and resolves the error (by fixing it and running the task again). How would I otherwise notice?

Indeed, that corresponds to what we discussed and I'm not criticising what you did. It's just that seeing in action, it doesn't seem like such a good idea anymore.

The user will notice because the status bullet is red and indicates a failure. So the failure information is not lost. The problem with displaying the failure message as an error flash message, is that it appears to be out of context. If several tasks have failed, there's no way to relate an error message to a specific task. Furthermore, if you are working in the BE module, you get those error messages on every screen view, no matter what operation your performed (unless it was a successful execution of that very task), which is very confusing.

So I think the failure bullet with the hover bubble is quite enough. The error message would still appear when a manual execution fails.

Actions #16

Updated by Francois Suter about 15 years ago

  • Status changed from Needs Feedback to Resolved

Committed a follow-up in r1130

As discussed I removed the permanent display of all failures as error messages in the list view, because of the confusion it caused and the bad readability. I changed the label of the failure status to indicate that people should move over the failure bullet to see the error message (this could be improved).

Thanks to the improved error reporting introduced in #4312, however, the failure message is indeed shown in the list view when the event has been executed manually in the BE module, so that there's a direct feedback about the failure.

Actions #17

Updated by Francois Suter over 12 years ago

  • Status changed from Resolved to Closed
Actions #18

Updated by Michael Stucki almost 11 years ago

  • Category set to scheduler
Actions #19

Updated by Michael Stucki almost 11 years ago

  • Project changed from 739 to TYPO3 Core
  • Category changed from scheduler to scheduler
Actions

Also available in: Atom PDF