Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add methods DelayStamp::delayFor() and DelayStamp::delayUntil(). #38480

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

Closed
wants to merge 1 commit into from
Closed

Add methods DelayStamp::delayFor() and DelayStamp::delayUntil(). #38480

wants to merge 1 commit into from

Conversation

Aerendir
Copy link
Contributor

@Aerendir Aerendir commented Oct 8, 2020

Q A
Branch? 5.x for features
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #38459, Related to #38463
License MIT
Doc PR symfony/symfony-docs#...

This PR adds two static factory methods:

  1. DelayStamp::delayFor()
  2. DelayStamp::delayUntil()

DelayStamp::delayFor()

Using the PHP relative DateTime formats, it is possible to create a DelayStamp using a way more simple syntax:

$delayStamp = DelayStamp::delayFor(30, DelayStamp::PERIOD_MINUTES);
$delayStamp = DelayStamp::delayFor(30, DelayStamp::PERIOD_WEEKS);
$delayStamp = DelayStamp::delayFor(30, DelayStamp::PERIOD_DAYS);

DelayStamp::delayUntil()

Passing a future DateTime, the method creates a DelayStamp.

$futureDate = new \DateTime('2050-08-28');
$delayStamp = DelayStamp::delayUntil($futureDate);

Supersedes #36512

  • Update CHANGELOG.md

@Aerendir
Copy link
Contributor Author

Aerendir commented Oct 8, 2020

Errors are not related to this PR.

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Thank you for this PR.

/**
* Apply this stamp to delay delivery of your message on a transport.
*/
final class DelayStamp implements StampInterface
{
public const PERIOD_SECONDS = 'seconds';
Copy link
Member

Choose a reason for hiding this comment

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

Please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this related to your comment about delayFor()?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we dont need a way to redefine time.

*
* @see https://www.php.net/manual/en/datetime.formats.relative.php#datetime.formats.relative
*/
public static function delayFor(int $units, string $period)
Copy link
Member

Choose a reason for hiding this comment

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

Please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not understanding: why?

Copy link
Member

Choose a reason for hiding this comment

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

We dont need to reinvent a way to define time intervals. We got the DateInterval, Either using that or a DateTime is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, should have I to add delayForDays() method?

Copy link
Contributor Author

@Aerendir Aerendir Oct 8, 2020

Choose a reason for hiding this comment

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

It is simply a shortcut, like the ones already exist in the class.

@Nyholm
Copy link
Member

Nyholm commented Oct 8, 2020

I would be happy with this PR if the only thing you add is this factory method DelayStamp::delayUntil(DateTimeInterface $datetime) and a test for that method.

@Aerendir
Copy link
Contributor Author

Aerendir commented Oct 8, 2020

I would be happy with this PR if the only thing you add is this factory method DelayStamp::delayUntil(DateTimeInterface $datetime) and a test for that method.

I added the method delayFor() as there are already the methods delayForSeconds(), delayForMinutes() and delayForHours().

As is a common need to postpone the execution and that this need doesn't limit to seconds, minutes or hours, I thought it have would been a good idea to add a generic method as a shortcut.

You are right: we already have DateTimeInterval object and we also have the \DateTime::modify() method: but a shortcut is always welcome, isn't it?

Symfony has a lot of shortcuts and this is one of the greatest things of this framework: it covers also the smallest details... And this is one of them.

I don't understand some of them nor I have never used them... but they are there and when it will come the time, I will be able to use them and be a bit more happy with my DX using Symfony.

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

I vote 👎 for this PR in the current state. I think it should be closed.

If you decided to follow my suggestion I would be happy to vote it up and make sure it gets merged.

I would be happy with this PR if the only thing you add is this factory method DelayStamp::delayUntil(DateTimeInterface $datetime) and a test for that method.

I have tried to explain myself that we dont need a new way to define time intervals. We also dont need existing methods to take an integer, convert to a datetime and then convert back to an integer.

@Aerendir
Copy link
Contributor Author

Aerendir commented Oct 8, 2020

@Nyholm , ok... I ask you to think about this for some time, please... May be you will arrive at a different conclusion, or may bb you will evaluate the tradoffs and decide that it is not a so big issue as you see it now to add a generic delayFor() method, also considering there already are three methods like it and that converting back to integer is not a so expensive operation.

I did the same thing in the other issues where we met: I arrived at the conclusion you were right, but in this case, really, I don't see the issue... But maybe I'm wrong... rather: probably I'm... Let me think at this for some time, too...

@maxhelias
Copy link
Contributor

maxhelias commented Oct 8, 2020

A "DateInterval" object is 100x better, less code and more flexibility.
Nothing prevents you from creating your own wrapper or DateInterval decorator with your "delayForMinutes" method in your project and putting your business need ?

@fabpot fabpot closed this Oct 8, 2020
fabpot added a commit that referenced this pull request Oct 8, 2020
…:delayUntil() (Nyholm)

This PR was squashed before being merged into the 5.x branch.

Discussion
----------

[Messenger] Add DelayStamp::delayFor() and DelayStamp::delayUntil()

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #38141
| License       | MIT
| Doc PR        |

This PR will revert the work by @Toflar in #38141. He added some helper methods and I want to add a generic factory method that adds a DateInterval.

This PR will also close #38480 and fix #38459. It is also related to a comment in #36512 (comment) that was liked by a few people.

Maybe adding both `DelayStamp::delayFor(\DateInterval)` and `DelayStamp::delayUntil(\DateTimeInterface)` is overkill. But this covers all the bases and I hope that it will be the last change to this small class.

Commits
-------

c5de1eb [Messenger] Add DelayStamp::delayFor() and DelayStamp::delayUntil()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Messenger] Implement an ExecuteAfterDateStamp
5 participants