Skip to content
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

Resumable scheduled tasks #36708

Merged
merged 8 commits into from
Jan 17, 2022
Merged

Resumable scheduled tasks #36708

merged 8 commits into from
Jan 17, 2022

Conversation

nikosdion
Copy link
Contributor

@nikosdion nikosdion commented Jan 16, 2022

Pull Request for Issue joomla-projects/soc21_website-cronjob#59

Pinging @ditsuke and @bembelimen since Scheduled Tasks is their baby and they're currently the only ones who can understand this PR.

Summary of Changes

Scheduled tasks can now return Status::WILL_RESUME to indicate they are not done and should be rescheduled immediately to resume execution.

This is useful for whenever you have long running tasks which would otherwise end up hitting a memory or timeout limit on your server. Some examples of such tasks:

  • Sending a newsletter with thousands of subscribers
  • Batch processing hundreds to thousands of images
  • Synchronising folder contents across different servers or with external services (“poor man's rsync”)

Testing Instructions

The “Task - Demo Tasks!” plugin has been updated with a new sample task called “Resumable task”.

Create a new task using Resumable Task.

Set it to run once every 10 minutes.

Enable Individual Task Logs and set the Log Filename to resumable.log.php.

Trigger the task scheduler. On each execution, the task has a 60% chance of resuming and 40% chance of finishing.

Actual result BEFORE applying this Pull Request

N/A — Joomla did not support resumable tasks.

Expected result AFTER applying this Pull Request

The administrator/logs/resumable.log.php file will contain something like this:

2022-01-16	13:21:15	INFO	Running task#01 'Resumable Example'.
2022-01-16	13:21:15	INFO	Task> Starting new task 1
2022-01-16	13:21:15	INFO	Task> Starting 1s timeout
2022-01-16	13:21:16	INFO	Task> 1s timeout over!
2022-01-16	13:21:16	INFO	Task> Task 1 will resume
2022-01-16	13:21:16	INFO	Task#01 needs to perform more work.
2022-01-16	13:21:23	INFO	Running task#01 'Resumable Example'.
2022-01-16	13:21:23	INFO	Task> Resuming task 1
2022-01-16	13:21:23	INFO	Task> Starting 1s timeout
2022-01-16	13:21:24	INFO	Task> 1s timeout over!
2022-01-16	13:21:24	INFO	Task> Task 1 is now complete
2022-01-16	13:21:24	INFO	Successfully finished task#01 in 1.00 (net 1.00) seconds.

As you can see the task can detect whether it's being resumed.

Documentation Changes Required

N/A. There is no documentation on scheduled tasks beyond the demo tasks plugin. The new resumable demo task is self–documenting.

Postscriptum

I have still not managed to find time to integrate scheduled tasks in my own software. I did have, however, the time to study the code and understand better how Scheduled Tasks work. I can already see that they are very appealing. I am looking forward to implementing an integration with them in the next minor versions of my software tentatively scheduled for early Q2 2022. If lazy scheduling works in real world sites as reliably as it does on my test servers it will be a veritable game changer for Joomla!. That's the first time in years I am ecstatic about new code added to Joomla, let alone code added in a minor release. Well done!

@joomla-cms-bot joomla-cms-bot added Language Change This is for Translators PR-4.1-dev labels Jan 16, 2022
@tecpromotion
Copy link
Contributor

I have tested this item ✅ successfully on b7d170b

Thanks @nikosdion

Nice feature


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36708.

Nicholas K. Dionysopoulos and others added 3 commits January 16, 2022 16:27
Co-authored-by: Brian Teeman <[email protected]>
Co-authored-by: Brian Teeman <[email protected]>
Co-authored-by: Brian Teeman <[email protected]>
@nikosdion
Copy link
Contributor Author

@tecpromotion Cheers! And thank you ever so much for the test!

@brianteeman Thank you for the comment language fixes :)

@richard67
Copy link
Member

@nikosdion I've allowed myself to apply the change suggestion for "impending".

I've also restored the previous test result because all changes after that were only in code comments.

@richard67
Copy link
Member

@nikosdion Ah, and I was so free to remove the emoji from the PR description. We made bad experience with that in past.

@richard67
Copy link
Member

I have tested this item ✅ successfully on d354d27


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36708.

Nicholas K. Dionysopoulos and others added 2 commits January 16, 2022 23:55
…esumable-mod-1

[CMS PR 36708] Revert use DateInterval
@nikosdion
Copy link
Contributor Author

@richard67 Can I ask an incidental question? You said “[...] remove the emoji from the PR description. We made bad experience with that in past”. Um... What kind of bad experience? I have used Emojis before. It sounds like there's a story to be told here. What have I missed?

@richard67
Copy link
Member

@richard67 Can I ask an incidental question? You said “[...] remove the emoji from the PR description. We made bad experience with that in past”. Um... What kind of bad experience? I have used Emojis before. It sounds like there's a story to be told here. What have I missed?

In past sometimes emojis in the title or the first so and so many characters ot the description was able to confuse the issue tracker, as far as I remember, and it also could cause Drone or Appveyor not being started, something like that.

I saw that Drone had not been started long time after the last commit, so I removed the emoji to be safe.

@richard67
Copy link
Member

I have tested this item ✅ successfully on 9962baf


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36708.

@nikosdion
Copy link
Contributor Author

Dang! I would have never thought an emoji would throw a spanner in the works like that. Thanks for the heads up. I'll just use text smileys from now on.

@richard67
Copy link
Member

Restored @tecpromotion 's test result since the changes after that were just doc bloc and reverting an unrelated change (which I just have tested).

@richard67
Copy link
Member

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36708.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jan 16, 2022
@bembelimen bembelimen added this to the Joomla 4.1.0 milestone Jan 17, 2022
@bembelimen bembelimen merged commit cb2f1e2 into joomla:4.1-dev Jan 17, 2022
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jan 17, 2022
@bembelimen
Copy link
Contributor

Awesome, thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Change This is for Translators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants