Skip to content

RFC: Add Script Startup Priorities #621

@wpferguson

Description

@wpferguson

Current script startup order

If scripts are started from a luarc file, then they start in the order they are listed in.

If script_manager is handling startup then it works like this:

  • script manager searches the lua directory for scripts and sorts them alphabetically
  • any lua file in a lib directory is ignored.
  • script_manager ignores itself and doesn't try to start a second copy
  • for each script that's found a check to see if it was running at darktable shutdown is made and if it was running it's started

Why does it matter?

Most lua-scripts rely on events to trigger actions. As each script starts it registers events and they are placed in a table for each event type. When an event is triggered the event is sent to the first script that registered, the script performs it's actions, the event is sent to the second script that registered, etc...

Most of the time the order scripts receive events in is not important. However, sometimes order is important. For instance:

  • Lua has an event called inter-script-communication
  • It can be used for cooperative multi tasking so that a long running script, such as cache generation, doesn't block the rest of the lua-scripts until it completes.
  • In the case of cooperative multitasking, the scheduler task should start first so that it doesn't have to wait for for each script to look at the event before getting to the scheduler. Or if I'm debugging the communications, then I would want the debugging script to start first so that it could show the communication before the action takes place.

Possible solutions

  • Dependencies - This was my first thought, but I think this would be a nightmare from building a dependency tree to ending up with circular dependencies.
  • Priorities - Much easier to implement. Much less prone to error. Dependencies probably offer finer control, but I'm not sure it's necessary.

Implementation

We already have a metadata block that is read before starting the script, so that would be the easiest, cleanest solution. A certain block of priorities should be reserved for "system"scripts such as scheduler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions