Skip to content

Single Server double execution #90

@maciekpaprocki

Description

@maciekpaprocki

I am not sure if i am not doing something stupid.

Seems that single server only works correctly if the commands are triggered at exactly the same time and are long enough.

Example

I run script:

php bin/console schedule:run &
php bin/console schedule:run &
$schedule->onSingleServer()
$schedule->addCommand('app:test-slack "Test message"')
       ->onSingleServer()
       ->identifiedBy('app:test-slack "Test message"')
        ->everyMinute();

everything fine

Then I do bash:

php bin/console schedule:run &
sleep 1
php bin/console schedule:run &

I receive two Slack messages

Then when I add sleep(2); inside of my app:test-slack I receive one again.

That means that lock only works until the other server is still running the command. That is potentially dangerous. The issue is, that some tasks can be very quick. Some servers might be delayed with triggering cron ( for example when the cache is not warmed )

Fix:

Lock should probably be for a minute and with a minimal timeout of 60 seconds. Not sure how it works from the symfony lock perspective. Don't think there's ready made mechanism and all implementations I can think of are a bit sketchy. Happy to implement though if pointed in right direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions