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

Question - success and fail events #17

Open
thim81 opened this issue Jun 6, 2016 · 4 comments
Open

Question - success and fail events #17

thim81 opened this issue Jun 6, 2016 · 4 comments

Comments

@thim81
Copy link

thim81 commented Jun 6, 2016

Hi Markus,

Another question, where I'm not sure how to handle an automated import process properly.

Situation:

  • a process dumps import files in a directory
  • a cron job scans the folder and imports them using the ImportEngind command
  • when success -> move file to "finished" folder and mail report
  • when fail -> move file to "failed" folder and mail report

How can I handle the success and fail events?
Is there a event in the ImportEngine to do this? I have seen the "prepare" event but I'm not sure which are the other events and what data they expose.

@mathielen
Copy link
Owner

Hi Tim,

You could do this via the finish event. But you have to figure yourself what "fail" and "success" means.

<service id="myimport.endpoint" class="Import\Endpoint\SomeService">
    <tag name="kernel.event_listener" event="data-import.finish.myimport" method="finish"/>
</service>

btw. you could also omit the ".myimport" suffix on the event's property, to have a catch-all method for all imports

And in SomeService:

public function finish(\Mathielen\DataImport\Event\ImportProcessEvent $event)
{
    /** @var $import \Mathielen\ImportEngine\Import\Import */
    $import = $event->getContext();
    $importRun = $import->getRun();

    //i.e. - there was at least one row, but none had been successfully written
    $hasFailed = $importRun->getStatistics()['processed'] > 0 && $importRun->getStatistics()['written'] === 0;

    //do something with the source? - if its a LocalFileStorage...
    $sourceStorage = $import->getSourceStorage;
    if ($sourceStorage instanceof LocalFileStorage && $hasFailed) {
        rename($sourceStorage->getFile(), ...)
    }
}

Did not test the code above, but you will get the idea.

Best regards
Markus

@thim81
Copy link
Author

thim81 commented Jun 6, 2016

Great!

I'll try to implement something like your example.

I'm thinking of making a small "example project" where I can combine all questions, would you be interested in something to attach it to your project for documentation?

@mathielen
Copy link
Owner

That would be awesome! I already thought about it the other day but didnt have the time to really get it started. I'm using the lib in a lot of different projects and could extend the demo with more advanced examples. Would be great to enable more developers to really understand what this library is all about.

@thim81
Copy link
Author

thim81 commented Aug 9, 2016

I'm going to give it try when I have the file-upload and validations working.

I could provide examples:

  • configuration for excell
  • service to process data
  • email processor command

And hopefully:

  • manual file-upload
  • validation

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

2 participants