Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write correct output when a process is skipped #13866

Merged
merged 2 commits into from Dec 16, 2018
Merged

Write correct output when a process is skipped #13866

merged 2 commits into from Dec 16, 2018

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Dec 16, 2018

Prevents errors like Error unserializing the following response from ?module=API&method=API.get&idSite=1&period=year&date=last3&format=php&trigger=archivephp: Skipped

When I tested locally it also avoided the message WARNING [2018-12-16 22:40:18] 5677 piwik/core/Common.php(271): Notice - unserialize(): Error at offset 0 of 7 bytes

refs DEV-1521

It is unserialized eg here: https://github.com/matomo-org/matomo/blob/3.x-dev/core/CronArchive.php#L867 and then evaluated here: https://github.com/matomo-org/matomo/blob/3.x-dev/core/CronArchive.php#L1433-L1463 (the other one expects an array of array but still works cause of empty check)

Prevents errors like ` Error unserializing the following response from ?module=API&method=API.get&idSite=1&period=year&date=last3&format=php&trigger=archivephp: Skipped`

When I tested locally it also avoided the message `WARNING [2018-12-16 22:40:18] 5677  piwik/core/Common.php(271): Notice - unserialize(): Error at offset 0 of 7 bytes `

refs DEV-1521
@tsteur tsteur added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Needs Review PRs that need a code review labels Dec 16, 2018
@tsteur tsteur added this to the 3.8.0 milestone Dec 16, 2018
@@ -142,7 +142,7 @@ private function start($piwikUrls)
if ($shouldStart === Request::ABORT) {
// output is needed to ensure same order of url to response
$output = new Output($cmdId);
$output->write('Skipped');
$output->write(serialize(array('skipped' => '1', 'nb_visits' => 0)));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the output doesn't really matter as long as it is a non-empty serialized array as we check with empty($metric['nb_visits']) etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory the response would need to depend on the caller but maybe in this case it isn't too important? checked it is used as well in ScheduledTaskRunner but it doesn't use the "abort" feature and the response format doesn't matter there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps in this case since the request is aborted, the output should be a null value? Like serialize(null)? Would have to change any uses to check that the value could be null. Or could be like API output w/ serialize(['result' => 'error']). I guess in any case callers would have to be aware of this new behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really an error I think. It is just not needed to execute it anymore basically (eg because the same job is already running). Setting null could be difficult maybe as it would be hard to differentiate between the aborted case and eg no response received etc.

So far we call CLI Multi only in Task Runner and Cron Jobs and there it is all fine. The abort feature is not really any documented feature for plugins so shouldn't be a problem. Could set it to $output->write(serialize(array('aborted' => '1'))) though and explain the output in the description of the constant... maybe that makes it more clear. A caller has to specifically implement some support to ABORT a command so I don't think it's a problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just changed the output... the ABORT feature in there is currently actually specifically in there for the archiver anyway.

@diosmosis diosmosis merged commit a424ffd into 3.x-dev Dec 16, 2018
@diosmosis diosmosis deleted the dev1521 branch December 16, 2018 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants