Code Monkey home page Code Monkey logo

fastq's Introduction

PHP FastQ

A simple queue processor wrote in PHP simple and fast. (Work in progress)

Proposal

id channel action data status tries after
1 payment MyApp\Sales\Payment::process { "var": 12 } 0 1 6542134421
2 payment Payment:payment { "var": 12 } 1 1 6542134421

data: json variables(no complex objects)

status: 1 = Processed | 0 = Holding | 2 - Failed

after: unixtimestamp (when to execute)

Lib actions:

  1. Read Queue = Collection
  2. Process Queue = execute the list
  3. Read Queue = List all activities
  4. Clear Queue = Clear processed actions(soft delete?)
  5. Trash Queue = Delete all processed action

How to use

<?php

$adapter = new FastQ\Adapters\Mysql(new PDO('...', 'user', 'pass'));

// Instanciate with dependency
$queue = new FastQ\Queue($adapter);

// Container callable
$queue->push('payment', 'Payment:process', '+5 seconds')->withData([
    'paymentId' => 'PAY-4880903345'
]);

// Static callable
$queue->push('payment', 'MyApp\\Payment::sendSMS', '+5 seconds')->withData([
    'paymentId' => 'PAY-4880903345'
]);

// Container Invokable call($receiver->__invoke())
$queue->push('payment', 'Receiver', '+5 seconds')->withData([
    'paymentId' => 'PAY-4880903345'
]);

Init FastQ

$ php vendor/bin/fastq init

Queue Structure Dump run only once

$ php vendor/bin/fastq dump 

Queue Structure Dump(SQLite) run only once

$ php vendor/bin/fastq dump sqlite

Proccess the queue and stop

$ php vendor/bin/fastq work

Proccess the queue holding

$ php vendor/bin/fastq work --listen
<?php

$adapter = new FastQ\Adapters\Mysql(new PDO('...', 'user', 'pass'));

// Instanciate with dependency
$queue = new FastQ\Queue($adapter);

$worker = $queue->pull('channelName');

// Execute the jobs
$worker->run();

// Response completed
var_dump($worker->getCompleted());

// Response failures
var_dump($worker->getFailures());

Todo

Make the consumer/worker commands How to implement async in Worker.php? ReactPHP?

Author

Leonardo Tumadjian

fastq's People

Contributors

leoqbc avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.