How to add Data Explorer Queries automatically from a Plugin?

I’ve got a suspicion there is a missing API here.

Data Explorer has become more and more useful as part of a Plugin workflow, but:

How do we reliably but tolerantly add Data Explorer queries from a third party plugin so we can fail gracefully without jeopardising the build but also retry each time in case Data Explorer is eventually installed?

Options I’ve explored:

  1. Poll Plugin: this cheats - the queries are added by the Data Explorer plugin itself
  2. Plugin fixtures - this appears to be problematic because the Data Explorer artifacts don’t seem to be guaranteed to be available during plugin initialisation - perhaps because the Data Explorer plugin is itself a third party plugin and not guaranteed to have been loaded? I guess I could try to use SQL via Ruby code to identify if the table exists?
  3. Migrations - I’ve written migrations but they need to harmlessly fail BUT NOT COMPLETE if Data Explorer plugin is not installed and there is no query table - the migrations should always run on rebuild until the Data Explorer plugin is installed and the table available so the queries can be added - that way from an admin point of view the solution is flexible and not depend on installation order. A failing migration should not jeopardise the build - is there a way to fail/put off a migration without stopping the build?
  4. Using a periodic scheduled job to check presence of both the data explorer plugin/query table and the required queies.
  5. Asking the admin to manually add them … yuk.

I guess I may try the SQL version of 2 next or maybe I’m missing something?

1 Like

I’ll take a look at my code that depends on the subscription plugin.

Why do you need data explorer? Is the point to create queries that an end user will use?

Yes, exactly that. Data Explorer is getting to a point where you can use it for administrative tasks for those with elevated roles in a process.

1 Like

You could have a job that runs to check that they are installed. It wouldn’t start until everything’s running.

But to make sure stuff isn’t broken you can check that some data explorer call is available. I think that’s what I’m doing for subscriptions, maybe. (It’s early and I haven’t opened my laptop.)

They added code last week that checks whether the chat plugin is loaded.

I think your problem is a race condition, though.

1 Like

Yes, that option is missing from the list of available options, I’ll add it.

But having a job running (which will continue to run periodically and check) seems a bit wasteful?

Good suggestion though (and I have considered this but it felt a bit …)

Maybe you just queue it to run once at startup? And it would run until the test for the plugin succeeded or die after some minutes?

1 Like

I like the enqueue on initialisation idea. That potentially overcomes the loading issue. I prefer that to the once every 24 hour option. Might give that a go! Thanks!

btw, the answer to this would also be generally useful for a broader set of problems.

I think just putting your test somewhere that it gets rescued if it fails is all you need. But can’t you just test to see if something like DataExplorer.something exists?

I do not know enough about using migrations to have considered using them for your use case. You could also have an endpoint that, say, the admin panel called, and it would check that you have your queries installed.

Now that I’m thinking, I am afraid the only problem I actually solved is adding the other plugin so that tests can work.