Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide queue component #492

Closed
samdark opened this issue Jun 4, 2013 · 16 comments
Closed

Provide queue component #492

samdark opened this issue Jun 4, 2013 · 16 comments

Comments

@samdark
Copy link
Member

samdark commented Jun 4, 2013

Useful for background jobs and all projects processing relatively large amounts of data.

Implementation can be designed the same way as cache i.e. base API + drivers such as:

Proposed base API:

abstract class Queue {
  // add job to the queue. $data will be passed as an argument to $callback and should be serializable
  public function push($callback, $data)
  {
  }

  // get a job and lock it queue for further processing
  public function get()
  {
  }
}
@bwoester
Copy link
Contributor

bwoester commented Jun 4, 2013

Another implementation might be based on System V message queues if PHP was compiled with --enable-sysvmsg

@cebe
Copy link
Member

cebe commented Jun 5, 2013

the local thing may use http://de2.php.net/manual/en/class.splqueue.php

@petrabarus
Copy link
Contributor

I really agree with this one.
The implementation on my project now is directly using AWS SDK for PHP v2. But if there is another layer of abstraction provided by Yii and an implementation for local development, I think this is really good.

@resurtm
Copy link
Contributor

resurtm commented Jun 6, 2013

A bit detalized proposal and architecture: https://gist.github.com/resurtm/5723626

Queue FSM states and transitions/actions:
queue-fsm

@yupe
Copy link
Contributor

yupe commented Jun 7, 2013

I've tried to implement it here https://github.com/yupe/yupe/tree/master/protected/modules/queue/components
Maybe you'd have found it useful

@nkostadinov
Copy link

That will be really great. Take a look at https://developers.google.com/appengine/docs/php/taskqueue/.

@nineinchnick
Copy link
Contributor

I almost finished a queue interface with three implementations that I'd like to propose as a base for work on queue components for Yii2.

I got:

  • a basic message queue,
  • pubsub,
  • message locking/reservation with timeout
  • a SQL, Redis and SystemV implementations

Should I make a WIP labeled PR or just make a branch and reference it here?

The current code is in my Yii 1 nfy module repo. I am going to port the whole module to Yii 2. There still are some issues to discuss about the current implementation.

@samdark
Copy link
Member Author

samdark commented Jan 12, 2014

PR is better.

@danschmidt5189
Copy link
Contributor

@samdark what is the queue component actually doing? (Besides adding/removing jobs from the queue.) Is it responsible for polling the queue and invoking callbacks as well?

Maybe I'm way off on the intended use-case, which to me is more like a glorified cache or db store:

public function uploadImage($uploadedImage)
{
    // Perform necessary stuff synchronously
    if (false === ($filename = $uploadedImage->save())) {
        return false;
    }

    // Perform time-consuming stuff asynchronously
    // Queue only stores the message. Listeners are responsible for processing them.
    Yii::$app->queue->add(new CreateThumbnailsTask($filename));
    return true;
}

If we're just defining an interface, why stop with push/pull? There are a lot of methods we might want to implement.

@nineinchnick
Copy link
Contributor

@danschmidt5189 I'm working on a general interface for a message queue that can be used to provide a job queue. I'm going to post a PR in very short time for review.

Such interface will come with few implementations to assist communication between concurrent requests. While working on it I considered creating an implementation that uses cache interface provided by the framework but found it very limiting. That validates the need for a message queue component in the framework or as a core extension.

@sergebezborodov
Copy link
Contributor

http://kr.github.io/beanstalkd/ is good solution for small-medium size projects. Has full control on tubes and tasks, really fast.
Here is my old implementation https://github.com/sergebezborodov/beanstalk-yii2

@lubosdz
Copy link
Contributor

lubosdz commented Jun 24, 2015

+1 if this can support concurrent/parallel jobs

Just a hint on possible implementation details:

@samdark
Copy link
Member Author

samdark commented Sep 28, 2015

It's now managed in https://github.com/yiisoft/yii2-queue

@samdark samdark closed this as completed Sep 28, 2015
@nineinchnick
Copy link
Contributor

@samdark I guess I should start splitting and moving my #2378 PR there too

@samdark
Copy link
Member Author

samdark commented Sep 29, 2015

@nineinchnick check what's there first.

@cebe cebe removed this from the 2.1.x milestone Sep 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.