Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Added onOneServer option to short run commands #8

Merged
merged 7 commits into from
Jul 13, 2020

Conversation

lionslair
Copy link
Contributor

This is to fore fill the Issue I previously created #6

Update README.md to include new method.
Update composer.json to require illuminate/cache.
Added onOneServer method and protected property to PendingShortScheduleCommand.
Refactored the run command to run one private method depending on the onOneServer value. OneOneServer still calls the processCommand method that do not have the onOneServer property set.
Add a test to ensure the cache item exists when onOneServer is true and run.

I am not sure if my test is the best way to ensure success. It should have the flag set in Cache if using the option.

I did a lot of debugging and testing in local and positive this works. It does for my needed use case. I did not want to leave logging in the code in order to test against so maybe you have a better way of testing this than I to assure yourself.

…re illuminate/cache. Added onOneServer method and protected property to PendingShortScheduleCommand. Refactored the run command to run one private method depending on the onOneServer value. OneOneServer still calls the processCommand method that do not have the onOneServer property set. Add a test to ensure the cache item exists when onOneServer is true and run
Copy link
Member

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this.

src/PendingShortScheduleCommand.php Outdated Show resolved Hide resolved
src/ShortScheduleCommand.php Outdated Show resolved Hide resolved
src/ShortScheduleCommand.php Outdated Show resolved Hide resolved
private function processOnOneServer()
{
if (Cache::missing($this->pendingShortScheduleCommand->cacheName())) {
Cache::add($this->pendingShortScheduleCommand->cacheName(), true, 60);
Copy link
Member

Choose a reason for hiding this comment

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

Why 60? Does the Laravel framework code also uses this value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The framework was using 3600 but I thought 60 seconds as this whole package is about sub minute tasks. I was thinking it should use
$this->pendingShortScheduleCommand->frequencyInSeconds()

so the expiration lasts only as long as the time between checks. However this should also depend on if you care about overlaps or not.

If it's too short could be an issue for some and same if it's too long. I assume the frameworks assumption no task will run for more than an hour.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's leave it at 60.

Should we also have to clean up this file when starting the loop? Right now, if we were to abort the loop at the wrong time, the file would stay, keeping to lock longer than it needs to be there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean in the situation the short-schedule:run is killed or dies then when it starts again that the command will be stuck because if the cache key is set? I have not experienced this. I am not 100% sure the running command actually terminates at the same time as as the loop.

So short-schedule:run can stop and I think the process that was running can still run and finish. It just will not be called again.

Worst case the key will expire in 1 minute. So in theory it should start running on one sever after 60 seconds in worst case scenario.

src/ShortScheduleCommand.php Outdated Show resolved Hide resolved
@freekmurze
Copy link
Member

The tests are failing for this PR, could you take a look at that?

@lionslair
Copy link
Contributor Author

@freekmurze have added a test and the tests now pass

@freekmurze freekmurze merged commit 4402fb7 into spatie:master Jul 13, 2020
@freekmurze
Copy link
Member

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants