public function queue($type, JsonArray $metaData = null)
    {
        $taskId = $this->generateId();

        if (null === $metaData) {
            $metaData = new JsonArray();
        }

        $metaData
            ->set(Task::SETTING_ID, $taskId)
            ->set(Task::SETTING_TYPE, $type)
            ->set('status', Task::STATE_PENDING)
            ->set(Task::SETTING_CREATED_AT, date('c'));

        $taskFile = new JsonFile($this->taskIdToFileName($taskId), null);
        $taskFile->setData($metaData->getData());
        $taskFile->save();

        if (!$this->createTaskFromMetaData($taskFile)) {
            unlink($taskFile->getFilename());
            throw new \InvalidArgumentException('Could not create task of type "' . $metaData->get('type') . '"');
        }

        $this->getConfig()->set($taskId, $metaData->getData());

        return $taskId;
    }