plugins: add support for scheduler's task-type declaration

Add a new register-task-types cli that will create missing task-type entries in the
scheduler according to:

- only create missing task-types (do not update them), but check that the
  backend_name field is consistent,
- each SWHTask-based task declared in a module listed in the 'task_modules'
  plugin registry field will be checked and added if needed; tasks which name
  start wit an underscore will not be added,
- added task-type will have:
  - the 'type' field is derived from the task's function name (with underscores
    replaced with dashes),
  - the description field is the first line of that function's docstring,
  - default values as provided by the swh.lister.cli.DEFAULT_TASK_TYPE (with
    a simple pattern matching to have decent default values for full/incremental
    tasks),
  - these default values can be overloaded via the 'task_type' plugin registry
    entry.

For this, we had to rename all tasks names (eg. `cran_lister` -> `list_cran`).

Comes with some tests.
This commit is contained in:
David Douard 2019-09-03 14:39:06 +02:00
parent e3c0ea9d90
commit 8d9deeb8f8
14 changed files with 233 additions and 41 deletions

View file

@ -10,4 +10,11 @@ def register():
return {'models': [NpmVisitModel, NpmModel],
'lister': NpmLister,
'task_modules': ['%s.tasks' % __name__],
'task_types': {
'list-npm-full': {
'default_interval': '7 days',
'min_interval': '7 days',
'max_interval': '7 days',
},
},
}

View file

@ -41,14 +41,16 @@ def get_last_update_seq(lister):
@app.task(name=__name__ + '.NpmListerTask')
def npm_lister(**lister_args):
def list_npm_full(**lister_args):
'Full lister for the npm (javascript) registry'
lister = NpmLister(**lister_args)
with save_registry_state(lister):
lister.run()
@app.task(name=__name__ + '.NpmIncrementalListerTask')
def npm_incremental_lister(**lister_args):
def list_npm_incremental(**lister_args):
'Incremental lister for the npm (javascript) registry'
lister = NpmIncrementalLister(**lister_args)
update_seq_start = get_last_update_seq(lister)
with save_registry_state(lister):
@ -56,5 +58,5 @@ def npm_incremental_lister(**lister_args):
@app.task(name=__name__ + '.ping')
def ping():
def _ping():
return 'OK'