Publishing strategy

Modules are placed in the ocli/ai/publish_strategy.py and ocli/ai/upload_strategy.py

The PublishStrategy class

The PublishStrategy class works the same way as the GeoJSONStrategy class.
It checks the Context object that contains the obj property, which encapsulates the Task object.
The Task object contains, in its configuration, the name of the task template (for example ocli.aikp.awesome.pack)

Custom implementation

Option 1

When the template of the AIKP is imported, it contains a RECIPE_DEFAULTS object in the config.py module of the AIKP where the module name, that contains the execute() method, is stored:

RECIPE_DEFAULTS = {
    'publish': 'publish', # publish.py
    ...}

Option 2

Implement publish(task:Task dry_run: bool, print_json: bool) function inside your TaskTemplate implementation


The PublishStrategy class imports this module and stores it in the _self._publish_ property. The public publish() method checks if an imported module exists.
If it does, the class executes this custom logic via the execute() method.
If it does not, the default publish_common() method is executed.

In an AIKP module, you should follow certain rules:

  1. The config.py module contains a RECIPE_DEFAULTS dictionary with the module name set as described above.

  2. The publish.py module must be placed in the AIKP directory.

  3. The publish.py module must contain the execute() method with passed Repo and Task parameters:

@pass_task
def execute(task: Task, dry_run: bool = False, print_json: bool = False):
    # your custom logic here

Custom module names

Option 1

You can set custom names for your GeoJSON, publish, or upload modules.
In this case, update the RECIPE_DEFAULTS dictionary accordingly:

RECCIPE_DEFAULTS = {
 'makegeojson': 'my_making_module', # means my_making_module.py
 'publish': 'my_awesome_publish',    # means my_awesome_publish.py
 'upload': 'my_upload_strategy'
}

Option 2

Implement makegeojson,publish and upload functions inside your TaskTemplate implementation

If we have two or more AIKP with the similar ‘publish’ or ‘makegeojson’ implementations

One possibility may be is:

  1. in ocli.ai.publish_strategy.py, you can add a class or method that encapsulates a custom logic:

def publish_ten_geojsons(task :Task) -> None:
    print('10 geojson files are being published...')  # your custom logic
  1. In the AIKP publish.py module, create the execute() method, for example:

@pass_task
def execute(task: Task, dry_run: bool = False, print_json: bool = False) -> None:
    from ocli.ai.publish_strategy import publish_ten_geojsons
    publish_ten_geojsons(task)
  1. Run ai publish post CLI command with example output:

10 geojson files are being published...

Note: the same approach may be used for the GeoJSON making strategy