{"id":22711225,"url":"https://github.com/yiicod/yii2-jobqueue","last_synced_at":"2025-04-13T15:12:56.894Z","repository":{"id":57087168,"uuid":"101396575","full_name":"yiicod/yii2-jobqueue","owner":"yiicod","description":"Multi processes job queue","archived":false,"fork":false,"pushed_at":"2018-04-27T15:56:12.000Z","size":36,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T15:12:52.922Z","etag":null,"topics":["multi-process","queue","yii2-jobs","yii2-queue"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiicod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-25T11:14:44.000Z","updated_at":"2021-03-14T15:02:13.000Z","dependencies_parsed_at":"2022-08-24T07:30:33.512Z","dependency_job_id":null,"html_url":"https://github.com/yiicod/yii2-jobqueue","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiicod%2Fyii2-jobqueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiicod%2Fyii2-jobqueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiicod%2Fyii2-jobqueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiicod%2Fyii2-jobqueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiicod","download_url":"https://codeload.github.com/yiicod/yii2-jobqueue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732487,"owners_count":21152852,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["multi-process","queue","yii2-jobs","yii2-queue"],"created_at":"2024-12-10T12:15:00.518Z","updated_at":"2025-04-13T15:12:56.852Z","avatar_url":"https://github.com/yiicod.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Yii Job Queue based on Illuminate Queue\n=======================================\n\n[![Latest Stable Version](https://poser.pugx.org/yiicod/yii2-jobqueue/v/stable)](https://packagist.org/packages/yiicod/yii2-jobqueue) [![Total Downloads](https://poser.pugx.org/yiicod/yii2-jobqueue/downloads)](https://packagist.org/packages/yiicod/yii2-jobqueue) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiicod/yii2-jobqueue/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiicod/yii2-jobqueue/?branch=master)[![Code Climate](https://codeclimate.com/github/yiicod/yii2-jobqueue/badges/gpa.svg)](https://codeclimate.com/github/yiicod/yii2-jobqueue)\n\nProvides Illuminate queues implementation for Yii 2 using mongodb as main storage.\n\n#### Base config:\n\n```php\n    'bootstrap' =\u003e [\n        'jobqueue'\n    ],\n    'components' =\u003e [\n        'jobqueue' =\u003e [\n            'class' =\u003e \\yiicod\\jobqueue\\JobQueue::class\n        ],\n        'mongodb' =\u003e [\n            'class' =\u003e '\\yii\\mongodb\\Connection',\n            'dsn' =\u003e 'mongodb://@localhost:27017/mydatabase',\n        ],        \n    ]\n```\n#### Console config (simple fork)\n```php\n    'bootstrap' =\u003e [\n        'jobqueue'\n    ],\n    'controllerMap' =\u003e [\n        'job-queue' =\u003e [\n            'class' =\u003e \\yiicod\\jobqueue\\commands\\JobQueueCommand::class,\n        ]\n    ],\n    'components' =\u003e [\n        'jobqueue' =\u003e [\n            'class' =\u003e \\yiicod\\jobqueue\\JobQueue::class\n        ],\n        'mongodb' =\u003e [\n            'class' =\u003e '\\yii\\mongodb\\Connection',\n            'dsn' =\u003e 'mongodb://@localhost:27017/mydatabase',\n        ],        \n    ]    \n```\n###### Start worker:\n\nRun worker daemon with console command: \n```php\n$ php yii job-queue/start\n```\n\nStop worker daemon:\n```php\n$ php yii job-queue/stop\n```\n#### Console config + PM2(http://pm2.keymetrics.io/). This variant more preferable for console configuration.\n```php\n    'bootstrap' =\u003e [\n        'jobqueue'\n    ],\n    'controllerMap' =\u003e [\n        'job-queue' =\u003e [\n            'class' =\u003e \\yiicod\\jobqueue\\commands\\WorkerCommand::class,\n        ]\n    ],\n    'components' =\u003e [\n        'jobqueue' =\u003e [\n            'class' =\u003e \\yiicod\\jobqueue\\JobQueue::class\n        ],\n        'mongodb' =\u003e [\n            'class' =\u003e '\\yii\\mongodb\\Connection',\n            'dsn' =\u003e 'mongodb://@localhost:27017/mydatabase',\n        ],        \n    ]        \n```\n###### pm2 config:\n```json\n    {\n      \"apps\": [\n        {\n          \"name\": \"job-queue\",\n          \"script\": \"yii\",\n          \"args\": [\n            \"job-queue/work\"\n          ],\n          \"exec_interpreter\": \"php\",\n          \"exec_mode\": \"fork_mode\",\n          \"max_memory_restart\": \"1G\",\n          \"watch\": false,\n          \"merge_logs\": true,\n          \"out_file\": \"runtime/logs/job_queue.log\",\n          \"error_file\": \"runtime/logs/job_queue.log\"\n        }\n      ]\n    }\n```\n###### Run PM2 daemons\n```bash\npm2 start daemons-app.json\n```\n\nNote: Don't forget configure mongodb\n\n\n#### Adding jobs to queue:\n\nCreate your own handler which implements yiicod\\jobqueue\\base\\JobQueueInterface \nOR extends yiicod\\jobqueue\\handlers\\JobQueue \nand run parent::fire($job, $data) to restart db connection before job process\n\n```php\nJobQueue::push(\u003c--YOUR JOB QUEUE CLASS NAME-\u003e\u003e, $data, $queue, $connection);\n// Optional: $queue, $connection\n```\n\nNote: $data - additional data to your handler\n\n#### Queue configuration:\n\nAdd jobqueue component with connections parameters, specially with \"MongoThreadQueue\" driver and connection name (\"default\" in example)\n```php\n'jobqueue' =\u003e [\n    'class' =\u003e \\yiicod\\jobqueue\\JobQueue::class,\n    'connections' =\u003e [\n        'default' =\u003e [\n            'driver' =\u003e 'mongo-thread',\n            'table' =\u003e 'yii-jobs',\n            'queue' =\u003e 'default',\n            'connection' =\u003e 'mongodb', // Default mongodb connection \n            'expire' =\u003e 60,\n            'limit' =\u003e 1, // How many parallel process should run at the same time            \n        ],\n    ]\n]\n```\nWorker will take jobs from mongo database and run them by thread with defined driver using \"mongo-thread\" command in the background\n\nAvailable events:\n_________________\n\nIn Worker::class:\n```php\nEVENT_RAISE_BEFORE_JOB = 'raiseBeforeJobEvent';\nEVENT_RAISE_AFTER_JOB = 'raiseAfterJobEvent';\nEVENT_RAISE_EXCEPTION_OCCURED_JOB = 'raiseExceptionOccurredJobEvent';\nEVENT_RAISE_FAILED_JOB = 'raiseFailedJobEvent';\nEVENT_STOP = 'stop';\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiicod%2Fyii2-jobqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiicod%2Fyii2-jobqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiicod%2Fyii2-jobqueue/lists"}