aureja / job-queue-bundle

安装数 : 18,310

依赖者: 0

建议: 0

安全性: 0

星标: 0

关注者: 2

分支: 2

开放性问题: 3

类型:symfony-bundle

v0.1.1 2016-11-20 18:47 UTC

This package is auto-updated.

Last update: 2024-09-15 03:08:38 UTC


README

使用Aureja/JobQueue进行作业队列管理的Symfony扩展包。

安装

步骤 1. 通过 Composer 安装

composer require aureja/job-queue-bundle "dev-master"

步骤 2. 将其添加到 AppKernel.php

class AppKernel extends Kernel
{
    /**
     * {@inheritdoc}
     */
    public function registerBundles()
    {
        $bundles = [
             // ...
             new Aureja\Bundle\JobQueueBundle\AurejaJobQueueBundle(),
             // ...
        ];
    }
}

步骤 3. 通过扩展Aureja模型或实现接口定义您的实体

<?php
// src/Acme/YourBundle/Entity/JobReport.php

namespace Acme\YourBundle\Entity;

use Aureja\JobQueue\Model\JobReport as BaseJobReport;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="aureja_job_report")
 */
class JobReport extends BaseJobReport
{
    /**
     * {@inheritdoc}
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * {@inheritdoc}
     *
     * @ORM\ManyToOne(targetEntity="Acme\YourBundle\Entity\JobConfiguration")
     * @ORM\JoinColumn(name="configuration_id", nullable=false, onDelete="CASCADE")
     */
    protected $configuration;
    
    // Your custom logic if needed.
}
<?php
// src/Acme/YourBundle/Entity/JobConfiguration.php

namespace Acme\YourBundle\Entity;

use Aureja\JobQueue\Model\JobConfiguration as BaseJobConfiguration;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="aureja_job_configuration")
 */
class JobConfiguration extends BaseJobConfiguration
{
    /**
     * {@inheritdoc}
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
    
    // Your custom logic if needed.
}

步骤 4. 更新您的数据库模式

步骤 5. 通过 app/config/config.yml 进行配置

# app/config/config.yml

aureja_job_queue:
    db_driver: orm
    class:
        model:
            job_configuration: Acme\YourBundle\Entity\JobConfiguration
            job_report: Acme\YourBundle\Entity\JobReport
            
    # Define queues as an array or as a string with values separated by a comma.
    queues:
        - default

步骤 6. 导入AurejaJobQueue路由文件

# app/config/routing.yml

aureja_job_queue:
    resource: "@AurejaJobQueueBundle/Resources/config/routing.xml"

步骤 7. 注册每分钟执行一次的计划任务

* * * * * php app/console aureja:job-queue:run