mozilla / active-data-recipes

A repository of various activedata queries and recipes
Mozilla Public License 2.0
9 stars 24 forks source link

Separating arguments processing out of recipe `run` function #78

Closed TrangNguyenBC closed 5 years ago

TrangNguyenBC commented 6 years ago

This PR solves a part of issue #40 Example of "config_durations" - need review

TrangNguyenBC commented 5 years ago

Hi @ahal. Following our discussion, I submitted the new PR which implements another structure of queries and recipes: Writing query involves of query context definition and query template, writing recipe involves of query calls (by only query names) and post-processing arguments.

TrangNguyenBC commented 5 years ago

Hi @ahal I refactor the code using some terms to make code clearer.

  1. Terms and meanings:
    • A context includes: name, definition, value. For example with this context definition below, the context name is sort_key (‘dest’) and the context value can be any int number: [['--sort-key'], {'type': int, 'dest': 'sort_key', 'default': 4, 'help': "Key to sort on (int, 0-based index)", }]
    • The context definition of query/run/recipe is an array of corresponding context definition. In detailed, query context definition (query_context_def) is an array of context definitions of all contexts which will be used in this query; Run context definition (run_context_def) is an array of context definitions of all contexts which will be used for post-processing in run function of this recipe; Recipe context definitions (recipe_context_def) is an array of context definitions of all contexts for this recipe (a combination of query_context_def and run_context_def).

In this case, “sort-key” is a specific run context of this recipe. A query also can have it own specific query context.

  1. Implementation:
    • The query file (*.queries - YAML file) has context names of common contexts and/or context definitions of specific query contexts. For example, in config_durations.queries we have in: {repo.branch.name: {$eval: branch}} with “branch” is a context name.
ahal commented 5 years ago

Hi @ahal I refactor the code using some terms to make code clearer.

1. Terms and meanings:

Thanks for the explanation, this is a lot clearer!