Comments

amateescu’s picture

Assigned: amateescu » Unassigned
Status: Active » Needs review
StatusFileSize
new45.95 KB

The attached patch does the following:

  1. moves system.queue.inc from system.module and batch.queue.inc from core/includes to a shiny new place in lib/Drupal/Core/Queue
  2. replaces the static method factory for getting a queue class with a queue() function in common.inc, much like the new cache system
  3. moves the queue test from core/modules/system/system.test to a new file in core/modules/simpletest/tests/queue.test

Status: Needs review » Needs work

The last submitted patch, queue-psr0.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new318 bytes
new45.96 KB

This should fix it.

amateescu’s picture

Issue tags: +PSR-0

Tagging.

aspilicious’s picture

You probably going to hate me but it would be nice if we could fix all the documentation in this issue. This issue isn't blocking any other critical issue (I think/hope) so we shouldn't rush things (like with the cmi patch).

+++ b/core/lib/Drupal/Core/Queue/QueueInterface.phpundefined
@@ -0,0 +1,108 @@
+   * Claim an item in the queue for processing.

Claims and newline after @param in that docblock

+++ b/core/lib/Drupal/Core/Queue/QueueInterface.phpundefined
@@ -0,0 +1,108 @@
+   * Delete a finished item from the queue.

Deletes

+++ b/core/lib/Drupal/Core/Queue/QueueInterface.phpundefined
@@ -0,0 +1,108 @@
+  /**
+   * Release an item that the worker could not process, so another
+   * worker can come in and process it before the timeout expires.
+   *
+   * @param $item

One line summary, newline between @param and @return and a description

+++ b/core/lib/Drupal/Core/Queue/System.phpundefined
@@ -0,0 +1,102 @@
+class System implements ReliableQueueInterface {

This class has no docblocks for functions.

Other similar issues are found, but it should be trivial to fix them.

neclimdul’s picture

It looks like a pretty straight forward to me. I kind-of prefer the previous factory but I'm lead to believe this is the rough standard atm so that's ok and suddenly some of those class names make no sense but that's also not this patches fault :)

I don't see a problem with these trivial doc changes if that's acceptable these days. They don't confuse any history.

I'm not sure there's anything to rush though, this is very straight forward.

aspilicious’s picture

By rush I mean, push this patch with partially fixed doc blocks. That way we have to reopen an issue specially for the docs.

amateescu’s picture

StatusFileSize
new3.96 KB
new46.26 KB

Ok, let's clean up the docs in here, but only because part of it was already done in #1315886: Clean up API docs for includes directory, files starting with A-C and I don't want to burden #1326664: Clean up API docs for system module (excluding subdirectories) any more with this trivial stuff.

Fixed all the items from #5 and a few more. Interdiff is from #3.

@neclimdul, I agree about the new class names not making any sense, I raised that point in #1323124-5: Convert file transfer system to PSR-0 but was 'shot' down by Crell in #8 :)

Crell’s picture

Status: Needs review » Needs work
+++ b/core/includes/common.inc
@@ -7843,3 +7843,98 @@ function drupal_get_filetransfer_info() {
+function queue($name, $reliable = FALSE) {
+  static $queues;
+  if (!isset($queues[$name])) {
+    $class = variable_get('queue_class_' . $name, NULL);
+    if (!$class) {
+      $class = variable_get('queue_default_class', 'Drupal\Core\Queue\System');
+    }
+    $object = new $class($name);
+    if ($reliable && !$object instanceof ReliableQueueInterface) {
+      $class = variable_get('queue_default_reliable_class', 'Drupal\Core\Queue\System');
+      $object = new $class($name);
+    }
+    $queues[$name] = $object;
+  }
+  return $queues[$name];
+}

This may be carried over from the previous code, but this is going to double-instantiate a queue object if you need a reliable interface. Rather, we can use http://us.php.net/class_implements to determine if the class implements an interface and then not even instantiate it if not.

If that's not appropriate to fix here because it's an existing bug, then we should open up a follow-up issue to fix it. I'm fine either way.

+++ b/core/modules/simpletest/tests/queue.test
@@ -0,0 +1,92 @@
+  function testQueue() {
+    // Create two queues.
+    $queue1 = queue($this->randomName());
+    $queue1->createQueue();
+    $queue2 = queue($this->randomName());
+    $queue2->createQueue();

So strictly speaking, we should not be using the queue() static factor in unit tests. We should be instantiating the actual class directly and configuring it directly, so that we have it in isolation. That does mean separate tests for System and Memory queues, which we should have anyway because those are separate pieces of code and should be tested independently (even if with similar tests, even if with tests that are the same and have a prepared object passed to them).

Very very few core tests do that properly, sadly, but it's a practice we should start following. May as well start now. :-)

Otherwise, this looks good to me. Thanks, amateescu!

23 days to next Drupal core point release.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new2.36 KB
new46.91 KB

Yep, that was carried over from the previous code as I didn't want to make any functional changes in this patch. Now that you mention it, I also thought that double instantiation is a little weird, so I'm not opposed to fixing it in here :)

Attached patch takes care of that and the tests. Interdiff is from #8.

lars toomre’s picture

Status: Needs review » Needs work
+++ b/core/includes/common.incundefined
@@ -7843,3 +7843,96 @@ function drupal_get_filetransfer_info() {
+ * @param $name
+ *   Arbitrary string. The name of the queue to work with.
+ * @param $reliable
+ *   TRUE if the ordering of items and guaranteeing every item executes at
+ *   least once is important, FALSE if scalability is the main concern.
+ *
+ * @return Drupal\Core\Queue\QueueInterface
+ *   The queue object for a given name.

When this is re-rolled, could we include variable type hinting here?

Also, since method getAllItems is not part of the interface, I think that our coding standards require that it get a complete docblock which includes @return directive.

aspilicious’s picture

StatusFileSize
new49.36 KB
+++ b/core/lib/Drupal/Core/Queue/System.phpundefined
@@ -0,0 +1,104 @@
+  /* Implementations of Drupal\Core\Queue\ReliableQueueInterface. */

We can't do this, we have to document each function.

I did this for you. Needs work for Crell his comments.

aspilicious’s picture

StatusFileSize
new49.37 KB

Small improvement

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new7.1 KB
new48.17 KB

I found a problem in my change from #10, the reliable check should go first.

Re: #11

When this is re-rolled, could we include variable type hinting here?

Fixed.

Also, since method getAllItems is not part of the interface, I think that our coding standards require that it get a complete docblock which includes @return directive.

Fixed.

Re: #12

We can't do this, we have to document each function.

This was already done in the DBTNG conversion, see http://drupalcode.org/project/drupal.git/blob/refs/heads/8.x:/core/lib/D... for example. But.. whatever, I've included your changes.

Needs work for Crell his comments.

Crell's comments were addressed in #10.

Interdiff is against #10.

Crell’s picture

Status: Needs review » Needs work
+++ b/core/includes/common.inc
@@ -7843,3 +7843,97 @@ function drupal_get_filetransfer_info() {
+    if ($class && $reliable && in_array('ReliableQueueInterface', class_implements($class))) {

When specifying an interface name in a string, like a class it needs to be fully qualified since that's what class_implements() should be returning.

+++ b/core/modules/simpletest/tests/queue.test
@@ -0,0 +1,120 @@
+  function queueTest($queue1, $queue2) {

Yeah, I'm being a pedant. :-) This method should be protected, since it's internal to this class. The test* methods (yay!) should be explicitly declared public. All methods should have their visibility specified.

I think I'm out of things to complain about otherwise. Nicely done. :-)

22 days to next Drupal core point release.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new2.08 KB
new48.23 KB

When specifying an interface name in a string, like a class it needs to be fully qualified since that's what class_implements() should be returning.

I had this in the back of my mind before starting to work on it, don't know why it came out wrong but thanks for catching it :)

This method should be protected, since it's internal to this class. The test* methods (yay!) should be explicitly declared public.

Fixed.

Interdiff is against #14.

Crell’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Queue/Memory.php
@@ -0,0 +1,107 @@
+  /**
+   * Counter for item ids.
+   *
+   * @var int
+   */
+  protected $id_sequence;

This should be lowerCamel case. Sorry I missed it before. :-(

That's it, then we should be done.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new1.05 KB
new48.22 KB

Done!

Crell’s picture

Status: Needs review » Reviewed & tested by the community

I can't imagine the bot having an issue with that small a change, and it will complain anyway if it does, so...

catch’s picture

Title: Convert DrupalQueue system to PSR-0 » Change notification for: Convert DrupalQueue system to PSR-0
Priority: Major » Critical
Status: Reviewed & tested by the community » Active

This looks great. We could do with a better name for the default reliably queue than 'System' but that problem pre-exists this patch, so committed/pushed to 8.x.

This will need a change notification - new factory added etc.

webchick’s picture

Title: Change notification for: Convert DrupalQueue system to PSR-0 » Convert DrupalQueue system to PSR-0
Priority: Critical » Major
Status: Active » Fixed

Courtesy of core office hours! http://drupal.org/node/1479680

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

neclimdul’s picture

Updated the change notice to reflect that a different factory was added not it was converted to use a factory. The documentation on the notice already showed the change.