GithubHelp home page GithubHelp logo

crunz's People

Contributors

andrewmy avatar arthurbarros avatar aviduda avatar bashgeek avatar codermarcel avatar davidsneighbour avatar digilist avatar drjayvee avatar ecofishrcr avatar erfan723 avatar falldi avatar hashnz avatar iluuu1994 avatar jhoughtelin avatar lavary avatar lucatacconi avatar m-hume avatar mareksuscak avatar marklittlewood avatar mindcreations avatar pablokowalczyk avatar philetaylor avatar radarhere avatar sadeghpm avatar simmonspaul avatar szepeviktor avatar timurbakarov avatar vinkla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crunz's Issues

Deprecate passing non-list array to \Crunz\Schedule::run second parameter

Description
As discussed in #14 passing non-list array in second parameters breaks ProcessUtil and is not supported by new versions of symfony/process.

Example
Non-list param:

<?php

use Crunz\Schedule;

$schedule = new Schedule();
$paramsTest = $schedule->run(
    PHP_BINARY,
    [
        '-v',
        '--ini' => false,
    ]
);

List of strings in param:

<?php

use Crunz\Schedule;

$schedule = new Schedule();
$paramsTest = $schedule->run(
    PHP_BINARY,
    [
        '-v',
        '--ini',
        '0',
    ]
);

Dont fail if one Task file throws an exception

If you have a ...Task.php file that throws an exception, none of the jobs run.

Ive been stung by this in past and without being able to call the task pragmatically (or atleast I cant work out how) you have to-do extra work to make sure this isn't preventing your jobs from being run.

Could try to submit a PR but would need some pointers ๐Ÿ˜„

Is it possible to execute crunz within PHP?

I'm trying to achieve something like what wordpress is doing, just running cronjobs cronless. I tried doing it with with exec, but they don't seem to be executing, and might be something wrong with my setup, not sure yet. I would like to know whats the state of crunz on this before i dig deeper.

New Feature: onOneServer

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.

Allow adding of an error callback to a Task

Currently there is no wat to add an additional "Error" callback in the same way as we can with ->before() and ->after().

Can the "addErrorCallback()" method be changed from private to public.

[BUG] everyTwoMinutes always run

OS: windows 10
PHP: 7.4

"lavary/crunz": "^3.2" vs "crunzphp/crunz": "^3.3"

$task->everyTwoMinutes(); or $task->cron('*/2 * * * *');

what i'm doing is running ./vendor/bin/crunz schedule:run repeatly

lavary : run as expected No event is due!
crunzphp: always run / execute task. No difference behaviour between everyMinute vs everyTwoMinutes

i'm also confirm that this bug is not happend for $task->everyThreeMinutes() or $task->cron('*/3 * * * *');

Tasks do not run after upgrade to latest version

Crunz version: 3.7.0

PHP version: 8.2

Operating system type and version: AlmaLinux v8.9.0

Description

After upgrading Crunz to the latest version, contents of my task (everything enclosed in $scheduler->run(function () {) were no longer triggered.

The file itself was triggered, which could be verified by placing a debug statement in the file somewhere, e.g. right after the $scheduler = new Schedule(); line

How to reproduce

$scheduler = new Schedule();
// E.g. sending a mail here does work
$task = $scheduler->run(function () {
    // Any code here does not get triggered
});
$task
    ->description('Example description')
    ->preventOverlapping()
    ->everyMinute();

return $scheduler;

can't figure out how to get sendOutputTo to work

Crunz version: 3.3.2

PHP version: 7.4.29/8.1.6

Operating system type and version:

CENTOS/MacOS Monterey

Description
using sendOutputTo command is not writing task output to file

How to reproduce
Simple task:

<?php
use Crunz\Schedule;

$schedule = new Schedule();

$taskToSchedule = $schedule->run(function () {
    echo 'Testing... 1, 2, 3', PHP_EOL;
});
    $taskToSchedule->everyMinute();
    $taskToSchedule->description('Description')
        ->sendOutputTo('/home/pinkele/public_html/testoutput.txt');

return $schedule;

I expect the output to be in the designated file, but it's not. This result is the same using CENTOS/PHP7.4.x or locally on my Mac using Monterey and either PHP7.4.x or 8.1.x

Possible Solution

Additional context
Cron job is configured to email me any output. I receive no emails, but if I remove the call to sendOutputTo, it behaves as expected and emails me the output of the task.

Return schedule as array of objects / arrays

Description
Its cool that you can run vendor/bin/crunz s:l but it would be really good if we could see these jobs displayed on a web interface.

Unfortunately I'm not quite sure how to approach this issue so im requesting it but cant produce a PR (which I know is rude sorry).

Happy to give it a shot but will need some pointers ๐Ÿ˜„

New log format

Description
It might be interesting to be able to have the log in a different format than those possible at the moment.

It might be interesting to have it in JSON format so as to be able to use it as input data for further batches or for a more immediate reading of the return data.

Example
It could be something like this:

{
    "execution_date_time" : "2023-09-27 10:38:00",
    "duration_seconds" : "60",
    "outcome" : "true",
    "output" : ".......",
    "error" : "......."
}

I am available to help you if you are interested.

Task activity status

Hi

Description
Sometimes you need to pause a task, and it would be nice if you could set a status for tasks.

  • Actively
  • Pause
  • Disabled

And so on, it would be good to think
Also display the "Status" column in the schedule:list table

Example

use Crunz\Schedule;

$scheduler = new Schedule();
$task = $scheduler->run('command/to/execute');
$task
    ->description('Task description')
    ->in('path/to/your/command')
    ->preventOverlapping()
    ->everyThirtyMinutes()
    ->weekdays()

    ->setStatusPause() //  Set status
;

return $scheduler;

logs by date

Description
Is there a possibility of logging the errors and output files name in date format?

Support for Symfony 7

Description
Due to release of Symfony 7, support of this version will be more than appreciated :)

Type error in str_replace call.

Crunz version: x.y.z
3.2.2

PHP version: x.y.z
8.1

Operating system type and version:
Ubuntu 22.04 LTS

Description
ProcessUtils::escapeArgument() is throwing a fatal error in PHP 8.1:

PHP Fatal error:  Uncaught TypeError: str_replace(): Argument #3 ($subject) must be of type array|string, bool given in vendor/crunzphp/crunz/src/ProcessUtils.php:84

Composer installing old version

Crunz version: 2.3.1

PHP version: 7.4.29

Operating system type and version:

MacOS Monterey (also to be deployed on RH)

Description
Composer installing older version of crunz. From CLI, I use composer require crunzphp/crunz and it installs v 2.3.1, which is marked EOL on the repo.

How to reproduce
from CLI, do composer require crunzphp/crunz

Possible Solution
I could go into composer.json and change version by hand, but shouldn't that happen automatically?

Additional context
I am using the latest version of composer. Not sure if the installed version might be dependent on what else I might have installed.

Non-numeric identifier for run individual task

Description
Currently we can run individual task only using dynamic numeric id
-t, --task=TASK Which task to run. Provide task number from schedule:list command.
Which does not guarantee that it does the same task every time.

What do you think for introduce non-numeric identifier which can be used alongside with numeric id for run command in more predictable way?

Example

<?php

use Crunz\Schedule;

$schedule = new Schedule();
$task = $schedule->run(PHP_BINARY . ' backup.php', ['--destination' => 'path/to/destination']);
$task
    ->identifier('backup')
    ->description('Copying the project directory');

return $schedule;

Usage:

Run
schedule:run --task=backup

List
crunz schedule:list


+---+------------+-----------------------+-------------+----------------+
| # | Identifier |            Task       | Expression  | Command to Run |
+---+------------+-----------------------+-------------+----------------+
| 1 |  backup    | Task description      | 0 * * * 1 * | scripts.php    |
+---+------------+-----------------------+-------------+----------------+

Configure the temporary directory instead of using \sys_get_temp_dir()

We have an error when using crunz with different projects on a same computer. The cache directory is computed in src/Application::getBaseCacheDir() using the function \sys_get_temp_dir().
So for all our projects, the cache is the same, but we need to have a different cache directory. (In our case we have some error)

A possible solution is to create an option in the configuration file and use it in the function src/Application::getBaseCacheDir().

Running task in sequence

I been trying to run task in serialize manner. Meaning after the first task is done should run another schedule task. Is this possible? Using the after function seems to fail with error Call to a member function isRunning() on null

The second command depends on the result processed from the first command.

Task Life Time functions don't respect the timezone

Crunz version: 3.4.1

PHP version: 8.2.8

Description
The timezone setting in crunz.yml is ignored for task life time checks in https://github.com/crunzphp/crunz/blob/v3.4.1/src/Event.php#L1191-L1213 . This causes tasks to run outside of specified time ranges.

How to reproduce
Have date.timezone=UTC in your php.ini and timezone: Europe/Berlin in your crunz.yml

crunz task:

<?php

use Crunz\Schedule;

$scheduler = new Schedule();
$scheduler
    ->run('echo "Hello World!"')
    ->everyMinute()
    ->between('12:00', '20:00');

return $scheduler;

play around with values for between and observe that it is following UTC times and not Europe/Berlin as configured.

Provide information about the file events were sourced from in schedule:list

Description
I want to know which file a particular scheduled event is defined in. This information is not currently exposed in either the table or JSON output format.

In my use-case I want to have this information in the JSON format so it can be machine-parsed.

Example
The table and JSON output of schedule:list should show the filename of the event/schedule.

Note
It is my intention to submit a PR for this feature.

Any way to delete a php script task file after its execution

First, thanks for this awesome library. I am using it for learning purposes. I have a few tasks in my tasks directory, all of which are php files running with the PHP BINARY by Crunz. I was wondering if there is a way to delete the php file after its execution.

Things that I have tried to achieve this:-

  1. Tried adding UNLINK(__FILE__); to the task php. But, I can't have it before return $schedule as the script won't complete and the task file gets deleted. I can't have it afterwards either, as anything after return $schedule doesn't run.
  2. I also tried running the scheduler to delete the file $schedule->run(PHP_BINARY . -r 'UNLINK(__FILE__'); But, __FILE__ here returns a value of Command line code and I tried various versions of it, but none of them work.

I am trying to self destroy the task once it has been executed from within the task php file itself. I am aware of using sh or bash to do this. But, I would really love to know if there was a way to achieve this from within the PHP file itself.

Sub-minute scheduling

We can mimic this now, but it would be great if it were built in.

Description
Technically jobs can only run every minute.

But it is possible to allow them to run, for example, every 30 seconds if you were to automatically schedule two jobs every minute, with one of them having a 30 second delay before executing.

So Job 1 runs immediately, Job 2 starts a 30 second timer, then runs.
Bam, we're cooking at twice a speed ๐Ÿ”ฅ

To do more frequent runs is similar, just needing to kick off as many jobs as needed with the requisite delays (or kick off one job that runs for the full minute and kicks off the jobs at the correct time - if doing this, technically any options are available for when to run).

Example

$task = $schedule->run(PHP_BINARY . ' email.php');
$task->every[One|Two|Three|Four|Five|Six|Ten|Twelve|Fifteen|Twenty|Thirty]Seconds();

I think the best option is to allow any integer divisor of 60, so: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30.

It could be that those shorter periods are too much - but a developer can decide that for themselves depending on what they're trying to accomplish.

Could also be something like:

$task = $schedule->run(PHP_BINARY . ' email.php');
$task       
    ->second([5, 10, 15, 20, 30])
    ->minute(['1-30', 45, 55])
    ->hour('1-5', 7, 8)
    ->dayOfMonth(12, 15)
    ->month(1);

This form may be confusing though if someone tries an invalid option for second.

Multiple Schedule objects from one task-file

Description
It would be very helpful to have a possibility to return multiple different Schedule objects from one task-file.
One possible usage scenario is external schedule source for Schedules.

Possible implementations are simple array or a Schedule-collection object.

Example

use Crunz\Schedule;
//...
$schedules = []; //  new ScheduleArrayObject();
forearch ($externalDefinitions as $definition) {
  $schedule = new Schedule();
  // configure $schedule
  // ...

  $schedules[] = $schedule;
}

return $schedules;

Getter for from, to task's parameters

In the Event.php class there are some public variables of the class and some public methods such as getExpression(), getId() which are very useful if you integrate the class and want to have details on the task you want to analyze.

Unfortunately there is no way to determine if the task has a lifetime configured by "from", "to" or "between" method.
Could be useful to have some getters for "from" and "to" configurations or have public variables to read that.

Theoretically the change could be quite simple.

You can add the variable "from" and "to" to the top of Event.php file with something like that:

/**
* Lifetime from.
*
* @var \DateTime|string
*/
public $from;

/**
* Lifetime to.
*
* @var \DateTime|string
*/
public $to;

and then modify class method from and to at line 448 and 460 with something like that:

/**
* Check if event should be on.
*
* @param string $datetime
*
* @return self
*/
public function from($datetime)
{
    $this->from = $datetime;
    return $this->skip(fn () => $this->notYet($datetime));
}

/**
* Check if event should be off.
*
* @param string $datetime
*
* @return self
*/
public function to($datetime)
{
    $this->to = $datetime;
    return $this->skip(fn () => $this->past($datetime));
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.