elixir-inspector / ua_inspector

User agent parser library
Apache License 2.0
127 stars 23 forks source link

Launch ua_inspector.download.databases without mix #10

Closed obsidienne closed 6 years ago

obsidienne commented 7 years ago

Hi,

I'm using distillery and I want to launch the databases download with my migration. How can I launch the download without mix (there is no mix in distillery) ?

Thanks

mneudert commented 7 years ago

Do you know if the Mix modules (those from Elixir itself) are available in a distillery release?

If yes you could manually call the download logic using ["--force"] as an argument to prevent confirmation.

If not there is no direct way at the moment. Until the download logic is properly extracted (will try to shift my focus to that) there is a dependency on at least Mix.shell/0 to return Mix.Shell.IO. If the Mix modules are not available at all you would need to provide a dummy class providing the calls to Mix.shell.info/1 and Mix.shell.error/1.

That still would require you to manually trigger an internal reload by restarting the application as there is no public interface to do that (yet!).

obsidienne commented 7 years ago

In a distillery release, MIX is totaly unavailable. But I can launch action before the application start, like DB migrations or downloading ua_inspector YML files from piwik.

The difficulty is load the YML files.

obsidienne commented 7 years ago

I can launch migration but I don't know how to launch the ua_inspector download as mix is unavailable

obsidienne commented 7 years ago

Another possibility is to allow in config something like that: Path.join(["#{:code.priv_dir(:myapp)}", "ua_inspector")

mneudert commented 7 years ago

The download is not yet possible without at least having some fake module for the Mix calls I mentioned. But you can move the database files in other ways, like including your priv/ folder or deploying them separately.

Using your example for configuration is actually allowed but cannot work because it is evaluated at compile time. Your compiled (and then deployed) configuration file would then include the local path returned when creating the release. So you need a different way to set the path, like a system environment

Or try Application.put_env(:ua_inspector, :database_path, Path.join([:code.priv_dir(:myapp), "ua_inspector"])) before starting the application and then restart the supervisor/application to force it to pick up the new values.

mneudert commented 7 years ago

By now I have extracted the download into a completely separate module.

To use it before I have released a new version (only checking some things like uncleaned ets tables and stuff) you can update your dependency configuration:

{:ua_inspector, github: "elixytics/ua_inspector", ref: "34aade30ed642d284772884204a8aa8fcb2b6d79"}

This will allow you to use UAInspector.download/0 to download all files without mix. Be sure to call UAInspector.reload/0 after the download finishes (done synchronously, just wrap it in a Task if you like) if the application is not getting a full restart to ensure the database files are properly read.

obsidienne commented 7 years ago

Hi,

With those modifications, i can remove the yml files from my repository.

Thanks you very much

Is it possible to change the config to use by :code.priv_dir() as a default path ?

mneudert commented 7 years ago

"Perhaps".

The problem is that the configuration is evaluated when building your release. If the path on the system creating the release and the path on the server is exactly the same you should be fine but I would not rely on that.

However you can simply set it manually in both your migration and application startup by calling Application.put_env/3 before calling UAInspector.download/0 and/or UAInspector.restart/0.

obsidienne commented 7 years ago

I think it will work.

When launching the app, I launch the migration. I think I can create another task downloading then reloading ua_inspector. In a task I think I can use priv_dir.

I will post here the result. Thanks

Le sam. 25 nov. 2017 à 12:24, Marc Neudert notifications@github.com a écrit :

"Perhaps".

The problem is that the configuration is evaluated when building your release. If the path on the system creating the release and the path on the server is exactly the same you should be fine but I would not rely on that.

However you can simply set it manually in both your migration and application startup by calling Application.put_env/3 before calling UAInspector.download/0 and/or UAInspector.restart/0.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/elixytics/ua_inspector/issues/10#issuecomment-346934658, or mute the thread https://github.com/notifications/unsubscribe-auth/ABMbAcp6pkc_BfJ8k7fCguC5rceCaj4rks5s5_jegaJpZM4P_9xK .

-- Claudio BERNARDES

mneudert commented 6 years ago

I have released a new version with the aforementioned changes to downloading/reloading. If you still encounter any problems please add a comment here or open a new issue.