jellelampaert/ci4_queue 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jellelampaert/ci4_queue

Composer 安装命令:

composer require jellelampaert/ci4_queue

包简介

CodeIgniter4 queuing system

README 文档

README

Queue tasks that depend on external services (like e-mail) in the database. Process the queue asynchronous (i.e. by using a cronjob), so the user does not have to wait for that service to respond.

Installation

Install the package through Composer.

Run the Composer require command from the Terminal:

composer require jellelampaert/ci4_queue

Once installed, make sure your database is setup correctly and run the migration

php spark migrate -all

Usage

How to load the library

$queue = new \jellelampaert\ci4_queue\Queue();
$queue->queue('email')->add(array(
    'to'        => 'test@example.com',
    'subject'   => 'This is a test',
    'message'   => 'Testing, attention please'
));

The queuing system has the following methods:

Queue::queue($queue)

Define the queue you want to use. Your application can have different queues, i.e. a queue for e-mails, a queue for webhooks, ...

Queue::add($data)

Add a task to the queue. The argument can be anything: a number, a string, an array, an object, ... Make sure to define a queuename first

$queue = new Queue();
$queue->queue('email')->add(array(
    'to'        => 'test@example.com',
    'subject'   => 'This is a test',
    'message'   => 'Testing, attention please'
));

Queue::clean($hours)

Delete all tasks from a queue that are processed more than x hours ago.

$queue = new Queue();
$queue->queue('email')->clean(24);

Queue::cleanAll($hours)

Delete all tasks from all queues that are processed more than x hours ago.

$queue = new Queue();
$queue->cleanAll(24);

Queue::delete($id)

Delete a task from the database.

$queue = new Queue();
$queue->delete(1);

Queue::getAllTasks()

Gets all tasks in the queue, whether they are processed or not

$queue = new Queue();
$queue->queue('email')->getAllTasks();

Queue::getAllUnprocessed()

Gets all unprocessed tasks from every queue in the database.

$queue = new Queue();
$queue->getAllUnprocessed();

Queue::getTask($id)

Gets a task by it's ID

$queue = new Queue();
$queue->getTask(1);

Queue::getUnprocessed()

Get all unprocessed tasks from a queue.

$queue = new Queue();
$queue->queue('email')->getUnprocessed();

Queue::setProcessed($id)

Sets a task as processed.

$queue = new Queue();
$queue->queue('email')->setProcessed(1);

Queue::setResponse($id, $data)

Sets the response of a task. This can be used for logging purposes or debugging

$queue = new Queue();
$queue->setResponse(1, 'HTTP Error 404');

License

This package is free software distributed under the terms of the MIT license.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固