Giter Site home page Giter Site logo

codeigniter4-queue's Introduction

The Illuminate Queue package for CodeIgniter 4

Inspired from https://github.com/agungsugiarto/codeigniter4-eloquent

Instalation

Include this package via Composer:

composer require masrodie/codeigniter4-queue

Setup services queue

Add redis config in .env

REDIS_HOST=localhost
REDIS_CLIENT=predis
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_SCHEME=tcp
REDIS_DB=0

Open App\Controllers\BaseController.php

add $this->queue = service('queue'); on function initController

//--------------------------------------------------------------------
// Preload any models, libraries, etc, here.
//--------------------------------------------------------------------
// E.g.:
// $this->session = \Config\Services::session();

 $this->queue = service('queue');;

Usage

Example job

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SendEmail implements ShouldQueue
{

    use InteractsWithQueue, Queueable, SerializesModels;

    public function fire($e, $payload) {
        $this->onQueue('processing');
        echo "FIRE\n";
        $email = \Config\Services::email();
        $config = [
            'protocol' => getenv('EMAIL_PROTOCOL'),
            'SMTPUser' => getenv('EMAIL_SMTP_USER'),
            'SMTPPass' => getenv('EMAIL_SMTP_PASS'),
            'SMTPHost' => getenv('EMAIL_SMTP_HOST'),
            'SMTPPort' => getenv('EMAIL_SMTP_PORT'),
            'SMTPCrypto' => 'ssl',
            'mailType' => 'html',
        ];
        $email->initialize($config);
        $email->setFrom('[email protected]', 'John Doe');
        $email->setTo($payload['to']);
        $email->setSubject('Hello');
        $email->setMessage('Hello email');
        $email->send();
        
        $e->delete();
    }

}

How to use in controller

<?php 

namespace App\Controllers;

class Home extends BaseController
{
	public function index()
	{
		$this->queue->push('\App\Jobs\SendEmail', ['to' => '[email protected]']);
	}
}

Run queue worker

php spark queue:work

More info usefull link docs laravel

License

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

codeigniter4-queue's People

Contributors

masrodjie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

codeigniter4-queue's Issues

error install

hii when i try install use composer require masrodie/codeigniter4-queue i have error
image
and when i try again use this composer require masrodjie/codeigniter4-queue i have an error again
image

ask

hii are this library is ready to use?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.