public function add(string $definitionID, $data = null, array $options = []): \BearFramework\Tasks
    {
        $app = App::get();
        $taskID = isset($options['id']) ? (string) $options['id'] : uniqid();
        $listID = isset($options['listID']) ? (string) $options['listID'] : '';
        $startTime = isset($options['startTime']) ? (int) $options['startTime'] : null;
        $this->lockList($listID);
        $list = $this->getListData($listID);
        if (isset($list[$taskID])) {
            $this->unlockList($listID);
            throw new \Exception('A task with the id "' . $taskID . '" already exists in list named \'' . $listID . '\'!');
        }
        $list[$taskID] = [1, $startTime]; // format version, start time
        $this->setListData($listID, $list);
        $taskData = [
            1, // format version
            $definitionID,
            $data
        ];
        $app->data->setValue($this->getTaskDataKey($taskID, $listID), gzcompress(json_encode($taskData)));
        $this->unlockList($listID);
        $this->dispatchEvent('addTask');
        return $this;
    }
public function add(string $definitionID, $data = null, array $options = []): \BearFramework\Tasks
    {
        $app = App::get();
        $taskID = isset($options['id']) ? (string) $options['id'] : uniqid();
        $listID = isset($options['listID']) ? (string) $options['listID'] : '';
        $startTime = isset($options['startTime']) ? (int) $options['startTime'] : null;
        $this->lockList($listID);
        $list = $this->getListData($listID);
        if (isset($list[$taskID])) {
            $this->unlockList($listID);
            throw new \Exception('A task with the id "' . $taskID . '" already exists in list named \'' . $listID . '\'!');
        }
        $list[$taskID] = [1, $startTime]; // format version, start time
        $this->setListData($listID, $list);
        $taskData = [
            1, // format version
            $definitionID,
            $data
        ];
        $app->data->setValue($this->getTaskDataKey($taskID, $listID), gzcompress(json_encode($taskData)));
        $this->unlockList($listID);
        $this->dispatchEvent('addTask');
        return $this;
    }
public function add ( string $ definitionID , $ data = null , array $ options = [ ] ) : \ BearFramework \ Tasks { $ app = App :: get ( ) ; $ taskID = isset ( $ options [ 'id' ] ) ? ( string ) $ options [ 'id' ] : uniqid ( ) ; $ listID = isset ( $ options [ 'listID' ] ) ? ( string ) $ options [ 'listID' ] : '' ; $ startTime = isset ( $ options [ 'startTime' ] ) ? ( int ) $ options [ 'startTime' ] : null ; $ this -> lockList ( $ listID ) ; $ list = $ this -> getListData ( $ listID ) ; if ( isset ( $ list [ $ taskID ] ) ) { $ this -> unlockList ( $ listID ) ; throw new \ Exception ( 'A task with the id "' . $ taskID . '" already exists in list named \'' . $ listID . '\'!' ) ; } $ list [ $ taskID ] = [ 1 , $ startTime ] ; // format version, start time $ this -> setListData ( $ listID , $ list ) ; $ taskData = [ 1 , // format version $ definitionID , $ data ] ; $ app -> data -> setValue ( $ this -> getTaskDataKey ( $ taskID , $ listID ) , gzcompress ( json_encode ( $ taskData ) ) ) ; $ this -> unlockList ( $ listID ) ; $ this -> dispatchEvent ( 'addTask' ) ; return $ this ; }
Adds a new tasks.

@param string $definitionID The ID of the definition.
@param mixed $data A task data that will be passed to the handler.
@param array $options Available options: id - the ID of the task, listID - the ID of the tasks list, startTime - the earliest time to start the task
@return \BearFramework\Tasks Returns an instance to itself.
@throws \Exception
Adds a new tasks .