Tripal
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Drupal\tripal_biodb\Task\BioTaskBase Class Reference
Inheritance diagram for Drupal\tripal_biodb\Task\BioTaskBase:
Inheritance graph
[legend]
Collaboration diagram for Drupal\tripal_biodb\Task\BioTaskBase:
Collaboration graph
[legend]

Public Member Functions

 __construct (?\Drupal\Core\Database\Connection $database=NULL, ?\Psr\Log\LoggerInterface $logger=NULL, ?\Drupal\tripal_biodb\Lock\SharedLockBackendInterface $locker=NULL, ?\Drupal\Core\State\StateInterface $state=NULL)
 
 setParameters (array $parameters=[])
 
 getTripalDbxClass ($class)
 
 performTask ()
 
 getId ()
 
 getStatus ()
 
 getLogger ()
 
- Public Member Functions inherited from Drupal\tripal_biodb\Task\BioTaskInterface
 validateParameters ()
 
 getProgress ()
 

Public Attributes

const TASK_NAME = 'task'
 
const STATE_KEY_DATA_PREFIX = 'tripal_biodb_'
 

Protected Member Functions

 prepareSchemas (array $schema_list)
 
 getSchemaLockName (\Drupal\tripal\TripalDBX\TripalDbxConnection $db)
 
 initId ()
 
 acquireTaskLocks ()
 
 releaseTaskLocks ()
 

Protected Attributes

 $id
 
 $connection
 
 $logger
 
 $locker
 
 $state
 
 $parameters = ['input_schemas' => [], 'output_schemas' => [], ]
 
 $inputSchemas = []
 
 $outputSchemas = []
 

Detailed Description

Defines the base class for tasks on one or more biological schemas.

Constructor & Destructor Documentation

◆ __construct()

Drupal\tripal_biodb\Task\BioTaskBase::__construct ( ?\Drupal\Core\Database\Connection  $database = NULL,
?\Psr\Log\LoggerInterface  $logger = NULL,
?\Drupal\tripal_biodb\Lock\SharedLockBackendInterface  $locker = NULL,
?\Drupal\Core\State\StateInterface  $state = NULL 
)

Creates a BioTaskBase object.

Parameters
\Drupal\Core\Database\Connection?,$connectionThe main database connection.
\Psr\Log\LoggerInterface?,$loggerThe logger.
\Drupal\tripal_biodb\Lock\SharedLockBackendInterface?,$lockerThe lock backend used to lock task and used schemas.
\Drupal\Core\State\StateInterface$stateDrupal state service.
See also
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Database.php/function/Database%3A%3AgetConnection/9.3.x
https://www.drupal.org/docs/8/api/database-api/database-configuration

Member Function Documentation

◆ acquireTaskLocks()

Drupal\tripal_biodb\Task\BioTaskBase::acquireTaskLocks ( )
protected

Lock what is needed before performing the task.

This method should be called by extending classes before starting their job on schemas (ie. in performTask()) as it will make sure a same task is not already running and it will also lock the schemas as needed.

Returns
bool TRUE if all the needed locks have been acquired, FALSE otherwise.

◆ getId()

Drupal\tripal_biodb\Task\BioTaskBase::getId ( )

{Returns the task identifier.This identifier is unique for a given task on a given set of schemas. It can be used to identify and retrieve an task to get its status while running from another independant process. It must only contain lower case alpha-numeric characters, underscores, dashes and dots. The task identifier should follow the following scheme: <task_name>-<dash_separated_schema_list> When a task works with more than one schema, the schema names should be ordered. The order could be alpha-numeric if it is not important or schema names could be ordered by argument order if this order is important. Schema name should be prefixed by the associated database name followed by a dot when it is not the default one.For example, a schema cloning task that clones the "chado" schema to a new schema named "alpha_chado" would use the task identifier: "clone-chado-alpha_chado".Another example would be a Chado data merging task that would merge the data of 2 Chado instances (chado1 and chado2)into a new schema (big_chado). The order of the 2 merged schema names is not relevant so they will be sorted alpha-numericaly. The target schema would come first as it will be unique while there could be more than 2 schemas to merge. So its task identifier would look like: "merge-big_chado-chado1-chado2"

Returns
string The complete task identifier string.
}

Implements Drupal\tripal_biodb\Task\BioTaskInterface.

◆ getLogger()

Drupal\tripal_biodb\Task\BioTaskBase::getLogger ( )

{Returns the logger used by this task.

Returns
\Psr\Log\LoggerInterface The task logger.
}

Implements Drupal\tripal_biodb\Task\BioTaskInterface.

◆ getSchemaLockName()

Drupal\tripal_biodb\Task\BioTaskBase::getSchemaLockName ( \Drupal\tripal\TripalDBX\TripalDbxConnection  $db)
protected

Returns the lock name to use for the given schema.

Parameters
\Drupal\tripal\TripalDBX\TripalDbxConnection$dbA schema connection.
Returns
string The lock name.

◆ getStatus()

Drupal\tripal_biodb\Task\BioTaskBase::getStatus ( )

{Returns a string describing current status of the performed task.This function returns the last known status, even if the task ended. In case of failure, this function may return the reason of the failure.

Returns
string A localized description.
}

Implements Drupal\tripal_biodb\Task\BioTaskInterface.

Reimplemented in Drupal\tripal_chado\Task\ChadoUpgrader, Drupal\tripal_chado\Task\ChadoRenamer, Drupal\tripal_chado\Task\ChadoRemover, Drupal\tripal_chado\Task\ChadoPreparer, Drupal\tripal_chado\Task\ChadoIntegrator, Drupal\tripal_chado\Task\ChadoInstaller, and Drupal\tripal_chado\Task\ChadoCloner.

◆ getTripalDbxClass()

Drupal\tripal_biodb\Task\BioTaskBase::getTripalDbxClass (   $class)

Gets the task-specific class for the specified category.

Returns the task-specific override class if any for the specified class category.

Parameters
string$classThe class category for which we want the specific class.
Returns
string The name of the class that should be used.

Reimplemented in Drupal\tripal_chado\Task\ChadoTaskBase.

◆ initId()

Drupal\tripal_biodb\Task\BioTaskBase::initId ( )
protected

Initializes task identifier.

◆ performTask()

Drupal\tripal_biodb\Task\BioTaskBase::performTask ( )

Example implementation of performTask().

This implementation should be replaced by extending classes (do not call parent::performTask method as it throws an error). It is provided as an example skeleton and for testing: first, it check parameters by calling ::validateParameters, it acquires required locks by calling ::acquireTaskLocks, manages lock failures, then it performs the task and finally releases the locks by calling ::releaseTaskLocks.

Returns
bool TRUE if the task was performed with success and FALSE otherwise. In some cases, exceptions can also be thrown in order to report major failures. FALSE would be returned if the task was completed but without the expected success.
Exceptions

Implements Drupal\tripal_biodb\Task\BioTaskInterface.

Reimplemented in Drupal\tripal_chado\Task\ChadoUpgrader, Drupal\tripal_chado\Task\ChadoRenamer, Drupal\tripal_chado\Task\ChadoRemover, Drupal\tripal_chado\Task\ChadoPreparer, Drupal\tripal_chado\Task\ChadoIntegrator, Drupal\tripal_chado\Task\ChadoInstaller, and Drupal\tripal_chado\Task\ChadoCloner.

◆ prepareSchemas()

Drupal\tripal_biodb\Task\BioTaskBase::prepareSchemas ( array  $schema_list)
protected

Parses schema names and extract the database name if one.

Parameters
array$schema_listAn ordered array of biological schema names that may be prefixed by a Drupal database key followed by a dot (see \Drupal\Core\Database\Database::getConnection()).
Returns
array An ordered array of \Drupal\tripal\TripalDBX\TripalDbxConnection objects.
See also
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Database.php/function/Database%3A%3AgetConnection/9.3.x
Exceptions

◆ releaseTaskLocks()

Drupal\tripal_biodb\Task\BioTaskBase::releaseTaskLocks ( )
protected

Release the locks used by the task.

This method should be called by extending classes once their job on schemas (ie. in performTask()) is over.

◆ setParameters()

Drupal\tripal_biodb\Task\BioTaskBase::setParameters ( array  $parameters = [])

{Sets task parameters.It sets (or sets again) task parameter before task execution. Only schema names are checked here, no other parameter validation are performed. Parameters are validate at runtime by ::performTask, just before the actual task is started.

Parameters
$parametersA associative array of parameters used to configure the task. The array should include the keys 'input_schemas' and 'output_schemas', both containing an array of ordered schema names (or an empty array). 'input_schemas' are biological schemas used for reading only which may be shared for reading with other concurrent tasks. 'output_schemas' are schemas that will be created or modified and must not be shared ( exclusive use) during the task. If a schema comes from a different database than the default one (ie. the one used by Drupal), the schema name must be prefixed by the database key name (and not the "target", as describbed in \Drupal\Core\Database\Database::getConnection()) followed by a dot.
Exceptions
}

Implements Drupal\tripal_biodb\Task\BioTaskInterface.

Member Data Documentation

◆ STATE_KEY_DATA_PREFIX

const Drupal\tripal_biodb\Task\BioTaskBase::STATE_KEY_DATA_PREFIX = 'tripal_biodb_'

Prefix for state keys to store data in Drupal State API.

◆ TASK_NAME

const Drupal\tripal_biodb\Task\BioTaskBase::TASK_NAME = 'task'

Name of the task.

Should be overridden by implementing classes.


The documentation for this class was generated from the following file: