Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions Classes/Annotations/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
* source code.
*/

use Doctrine\Common\Annotations\Annotation as DoctrineAnnotation;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;

/**
* @Annotation
* @DoctrineAnnotation\Target("METHOD")
* @NamedArgumentConstructor
* @Target("METHOD")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can @Target now be resolved, even though it's no longer imported "properly"?

@robertlemke robertlemke May 17, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest – I also wondered about it.But the Flow @around annotation does the same and @Annotation doesn't have to be imported, either. It seems to work. 🤷🏻

*/
#[\Attribute(\Attribute::TARGET_METHOD)]
final class Defer
{
/**
Expand All @@ -32,15 +34,16 @@ final class Defer
public $options;

/**
* @param array $values
* @throws \InvalidArgumentException
* @param string|null $queueName
* @param array|null $options
* @param string|null $value
*/
public function __construct(array $values)
public function __construct(?string $queueName = null, ?array $options = null, ?string $value = null)
{
if (!isset($values['value']) && !isset($values['queueName'])) {
throw new \InvalidArgumentException('A Defer annotation must specify a queueName.', 1334128835);
if ($value === null && $queueName === null) {
throw new \InvalidArgumentException('A Defer attribute must specify a queueName.', 1334128835);
}
$this->queueName = isset($values['queueName']) ? $values['queueName'] : $values['value'];
$this->options = isset($values['options']) ? $values['options'] : [];
$this->queueName = $queueName ?? $value;
$this->options = $options ?? [];
}
}
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ Neos Flow package that allows for asynchronous and distributed execution of task
}
```

or use attributes instead of annotations (PHP 8.0 and later):

```php
use Flowpack\JobQueue\Common\Annotations as Job;

class SomeClass {

#[Job\Defer(queueName: "some-queue")]
public function sendEmail($emailAddress)
{
// send some email to $emailAddress
}
}
```

*Note:* The method needs to be *public* and it must not return anything

5. **Start the worker (if required)**
Expand Down