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

How to suppress printing execution time using $this->taskExec() ? #383

Closed
disharmonized opened this issue Jul 20, 2016 · 7 comments
Closed

Comments

@disharmonized
Copy link

How to suppress printing execution time using $this->taskExec()? I have my own implemented execution time counter and i want to use it, not robo's version. Are there any opportunities to achieve that?

I am using 1.0.0beta1 robo's version.

@greg-1-anderson
Copy link
Member

Robo prints success/error results, including execution time, from the constructor of the Result object. This gives clients no opportunity to suppress this output.

Ideally, this would be refactored in a future version of Robo. In the 1.x timeframe, the best we could do would be to provide some sort of static variable to disable the result output. I'm not sure if that would be worth the overhead.

Could you provide more details on your use case? e.g. What would your desired output (including your custom time counter output) look like?

@disharmonized
Copy link
Author

Ok, here's my case:

class RoboFile extends \Robo\Tasks
{
    public function exportFromMySql()
    {
        $taskStartTime = time();

        $sql = 'select * from bigtable;';
        $output = '~/output/out.csv';

        $this->taskExec('mysql')
            ->arg('testdb')
            ->arg('--host=localhost')
            ->arg('--port=1234')
            ->arg('--user=test')
            ->arg('--password=test')
            ->arg('--quick')            
            ->arg(' -c "' . $sql . '" > ' . $output)
            ->printed(true)
            ->run()
            ->stopOnFail();

        //it prints execution time like
        //Done for 05:10:45
        $this->say('Done for ' . Util::getFormattedExecutionTime($taskStartTime, time()));

        //and after this robo prints it's own execution time output, which is already unnecessary for me

    }

    public function importToMongoDb(){
        //similar task
    }
}

It will be very handy to have opprotunity to change behaviour of Result output, i.e disable it, format it, whatever.

@disharmonized
Copy link
Author

disharmonized commented Jul 21, 2016

In the 1.x timeframe, the best we could do would be to provide some sort of static variable to disable the result output

I think that will be enough for me.

@ipeevski
Copy link
Contributor

Static variable is fine. It should disable both the starting and ending output.

@greg-1-anderson
Copy link
Member

I refactored the Config class to make it easier to reference from other classes (Config no longer contains a reference to the Container). TaskIO now checks Config::isSuppressed() before doing output. Things emitted by say are not affected.

Some things I realized in working on that PR:

  • Tasks should not care about output; they should just use TaskIO.
  • Robo commands should not change the default output formatting; they should rely on the application to do that.
  • Applications that are built on top of Robo can initialize up their own DI container if they would like to change the way things work (e.g. output). Modifying the container has to happen at the application layer, because a lot of objects will already have been created by the time the command runs, by which time it will be too late to modify most of the shared (singleton) objects in the container.

As far as this feature request is concerned, I think it would be better to submit a PR to robo to change the formatting of the execution time universally rather than try to turn off the default output and supply your own preferred time formatter.

@greg-1-anderson
Copy link
Member

@DavertMik: Please confirm this is not supported & close. Folks can turn off all task output via --supress-messages; otherwise, they cannot control how Robo does progress output unless they make their own standalone application.

@greg-1-anderson
Copy link
Member

This can be controlled if you use Robo as a framework to create your own application; see framework.md. Other use-cases not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants