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

Task Scheduler Like Cron job #154

Open
lablnet opened this issue Mar 5, 2019 · 9 comments · May be fixed by #324
Open

Task Scheduler Like Cron job #154

lablnet opened this issue Mar 5, 2019 · 9 comments · May be fixed by #324
Assignees
Labels
enhancement New feature or request Feature Request

Comments

@lablnet
Copy link
Member

lablnet commented Mar 5, 2019

There should be package that allow to handle task scheduler / cron job cross platform

@peter279k
Copy link
Member

peter279k commented Mar 23, 2019

The Cron job has the two key components.

  • Cron expression parser.
    It includes specific time.
  • Cron job task manager/scheduler.

Should we implement these all components?

@peter279k
Copy link
Member

You also mention about the cross platform.

I am not familiar with the cron job task on Windows.

I also am familiar with cron job on Linux.

@lablnet
Copy link
Member Author

lablnet commented Mar 23, 2019

Yes should implemented all components.

in windows there is Task Scheduler

when you send your proposal as a pull request i will add Win task scheduler support

write in such a way it has option to add support for windows

@peter279k
Copy link
Member

peter279k commented Mar 24, 2019

@lablnet, when I think this deeply, I found the following way to do Cron job package to support cross platform.

  • Using the scheduler.php to let this program run on every minute.
  • On every minute, we check the specific job should be executed.
  • We can use the log file or DB to store every task current execution time.

@lablnet
Copy link
Member Author

lablnet commented Mar 24, 2019

@peter279k Yes but this approach has few drawbacks

Using the scheduler.php to let this program run on every minute

First if any developer want to set schedule to set for 30 seconds then what result expected?

Also i think this make framework slightly slower

How can we execute scheduler.php on every mints, without task scheduler or cron?

The approach i think
there should be four files

  • AbstractScheduler.php => expression parser
  • Cron.php => Crons commands {extend AbstractScheduler}
  • Schedule.php => Task Scheduler {extend AbstractScheduler}
  • Scheduler.php => Scheduler which use {Cron or Schedule}
    Both class Cron and Schedule should have same methods
    we can do following in Scheduler,php
namespace Zest\Scheduler;

class Scheduler
{
      public function __construct()
     {
           $this->scheduler = php_os() === 'win' ? new Schedule() : new Cron();
     }
}

What do you think?

@peter279k
Copy link
Member

peter279k commented Mar 24, 2019 via email

@lablnet
Copy link
Member Author

lablnet commented Mar 24, 2019

Sure, so we can start before started actual development it good to write Contracts First
it let me to starts write schedule.php part
so you can write Contracts/Interfaces and pull here => https://github.com/zestframework/Zest_Framework/tree/master/src/Contracts
with sub folder

the interface name should same as class
we can use somthing like
`use \Zest\Contracts\Sitemap\SItemapIndex as SitemapIndexContract``

@lablnet lablnet pinned this issue Mar 24, 2019
@peter279k
Copy link
Member

peter279k commented Mar 24, 2019

@lablnet, consider following code:

$jobs = [
    [new CronExpression('cron job time'), new TaskName()],
    [new CronExpression('cron job time'), new TaskName()],
];

$scheduler = new Schedule($jobs);
$scheduler->run();

And let the task be interface so that we can let developers follow Task interface to customize the Task class.

What do you think about that?

@lablnet
Copy link
Member Author

lablnet commented Mar 24, 2019

Yes you are right

but instead of saying CronExpression it better say TaskExpression or SchedulerExpression

@ossamamehmood ossamamehmood unpinned this issue Sep 29, 2019
@lablnet lablnet pinned this issue Nov 27, 2020
lablnet added a commit that referenced this issue Nov 27, 2020
@lablnet lablnet linked a pull request Nov 27, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Feature Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants