idmtools.core.task_factory module

Define our tasks factory. This is crucial to build tasks when fetching from the server.

Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.

class idmtools.core.task_factory.DynamicTaskSpecification(task_type: Type[ITask], description: str = '')

Bases: TaskSpecification

This class allows users to quickly define a spec for special tasks.

__init__(task_type: Type[ITask], description: str = '')

Initialize our specification.

Parameters:
  • task_type – Task type to register

  • description – Description to register with task

get(configuration: dict) ITask

Get an instance of our task using configuration.

Parameters:

configuration – Configuration keyword args.

Returns:

Task with configuration specified

get_description() str

Get description of our plugin.

Returns:

Returns the user-defined plugin description.

get_type() Type[ITask]

Get our task type.

Returns:

Returns our task type

class idmtools.core.task_factory.TaskFactory

Bases: object

TaskFactory allows creation of tasks that are derived from plugins.

DEFAULT_KEY = 'idmtools.entities.command_task.CommandTask'
__init__()

Initialize our Factory.

register(spec: TaskSpecification) NoReturn

Register a TaskSpecification dynamically.

Parameters:

spec – Specification to register

Returns:

None

register_task(task: Type[ITask]) NoReturn

Dynamically register a class using the DynamicTaskSpecification.

Parameters:

task – Task to register

Returns:

None

create(key, fallback=None, **kwargs) ITask

Create a task of type key.

Parameters:
  • key – Type of task to create

  • fallback – Fallback task type. Default to DEFAULT_KEY if not provided

  • **kwargs – Optional arguments to pass to the task

Returns:

Task with option specified