crunzphp / crunz

A PHP-based job scheduler
MIT License
176 stars 16 forks source link

New Feature: onOneServer #42

Closed gennadiylitvinyuk closed 1 year ago

gennadiylitvinyuk commented 1 year ago

Description
An option to indicate that the task should run on only one server, similar to laravel's onOneServer like described in https://laravel.com/docs/9.x/scheduling#running-tasks-on-one-server

It is not possible to achieve the same results with preventOverlapping because the current implementation of preventOverlapping allows passing only locks implementing BlockingStoreInterface. It leads task execution once per server, but not in the same time.

PabloKowalczyk commented 1 year ago

Hello, blocking store is not required, it was fixed in docs and code do not acquire blocking locks. preventOverlapping should deliver same functionality as onOneServer.

Did you test preventOverlapping with remote store like PDO?

gennadiylitvinyuk commented 1 year ago

Unfortunately I didn't mention it, I refer to 3.4 but in 3.5 it is still the same

The check for BlockingStoreInterface is still there, if I understand it correctly.

https://github.com/crunzphp/crunz/blob/9148a14e164226aa164f585b7bca648bf3bae20f/src/Event.php#L721-L732

And yes, I tried it with PDO Store

PabloKowalczyk commented 1 year ago

The check for BlockingStoreInterface is still there, if I understand it correctly.

Yes, but StoreInterface is also accepted. Symfony changed Lock component in 5.x.

And yes, I tried it with PDO Store

Does it work?

gennadiylitvinyuk commented 1 year ago

No, at least in v3.4 (PHP 7.4) there is no 'Symfony\Component\Lock\StoreInterface available. That leads for example to Exception

In Event.php line 729:

  Instance of 'Symfony\Component\Lock\BlockingStoreInterface' or 'Symfony\Component\Lock\StoreInterface' is expected, 'Symfony\Component\Lock\Store\DoctrineDbalStore' provided  
PabloKowalczyk commented 1 year ago

Which Symfony Lock version?

gennadiylitvinyuk commented 1 year ago

Which Symfony Lock version?

symfony/lock v5.4.10

PabloKowalczyk commented 1 year ago

OK, looks like bug in Crunz, will be fixed soon.

PabloKowalczyk commented 1 year ago

@gennadiylitvinyuk please try https://github.com/crunzphp/crunz/pull/44

gennadiylitvinyuk commented 1 year ago

@gennadiylitvinyuk please try #44

Yes, it works this way