Giter Site home page Giter Site logo

syliusschedulercommandplugin's Introduction

License CI - Analysis CI - Sylius Version Total Downloads

Scheduler Command Plugin

Schedule Symfony Commands in your Sylius admin panel.

Commands list

Commands

Scheduled Commands list

Scheduled Commands

Features

  • See the list of planned command
  • Add, edit, enable/disable or delete scheduled commands
  • For each command, you have to define :
    • Name
    • Selected Command from the list of Symfony commands
    • Based on Cron schedule expression see Cron formats
    • Output Log file prefix (optional)
    • Priority (highest is priority)
  • Run the Command immediately (at the next passage of the command synolia:scheduler-run)
  • Run a Command juste one time (from history page clic on Launch a command button)
  • Download or live view of log files directly from the admin panel
  • Define commands with a Factory (from a Doctrine migration, for example)

Requirements

Version
PHP ^8.0
Sylius ^1.10

Installation

  1. Add the bundle and dependencies in your composer.json :

     composer config extra.symfony.allow-contrib true
     composer req synolia/sylius-scheduler-command-plugin
    
  2. Apply migrations to your database:

     bin/console doctrine:migrations:migrate
    
  3. Launch Run command in your Crontab

     * * * * * /_PROJECT_DIRECTORY_/bin/console synolia:scheduler-run
    
  4. (optional) Showing humanized cron expression

     composer require lorisleiva/cron-translator
    
  5. Till symfony/recipes-contrib is updated for the v3, you must add sylius_scheduler_command.yaml from install/Application/config/{packages,routes} to your project by respecting the same folder architecture.

     cp -R vendor/synolia/sylius-scheduler-command-plugin/install/Application/config/packages/* config/packages/
     cp -R vendor/synolia/sylius-scheduler-command-plugin/install/Application/config/routes/* config/routes/
    

Usage

  • Log into admin panel
  • Click on Scheduled commands in the Scheduled commands section in main menu to manage your Scheduled commands
  • Click on Scheduled commands history in the Scheduled commands section in main menu to see history of commands

Fixtures

Inside sylius fixture file config/packages/sylius_fixtures.yaml you can add scheduled command fixtures to your suite.

sylius_fixtures:
    suites:
        my_fixture_suite:
            fixtures:
                scheduler_command:
                    options:
                        scheduled_commands:
                            -
                                name: 'Reset Sylius'
                                command: 'sylius:fixtures:load'
                                cronExpression: '0 0 * * *'
                                logFilePrefix: 'reset'
                                priority: 0
                                enabled: true
                            -
                                name: 'Cancel Unpaid Orders'
                                command: 'sylius:cancel-unpaid-orders'
                                cronExpression: '0 0 * * *'
                                priority: 1
                                enabled: false

Commands

synolia:scheduler-run

Execute scheduled commands.

  • options:
    • --id (run only a specific scheduled command)

Run all scheduled commands : php bin/console synolia:scheduler-run

Run one scheduled command : php bin/console synolia:scheduler-run --id=5

synolia:scheduler:purge-history

Purge scheduled command history greater than {X} days old.

  • options:
    • --all (purge everything)
    • --days (number of days to keep)
    • --state (array of schedule states)
    • --dry-run

Example to remove all finished and in error scheduled commands after 7 days :

php bin/console synolia:scheduler:purge-history --state=finished --state=error --days=7

Optional services

services:
...
    # By enabling this service, it will be requested to vote after the other EveryMinuteIsDueChecker checker.
    # Using some cloud providers, even if the master cron is set to run every minute, it is actually not run that often
    # This service allows you to set a soft threshold limit, so if your provider is actually running the master cron every 5 minutes
    # This service will execute the cron if we are still in the threshold limit ONLY IF it was not already executed another time in the same range.
    #
    # CONFIGURATION SCENARIO: cron set to be run at 01:07 in the scheduler command plugin
    #
    # SCENARIO CASES AT 1 CRON PASS EVERY 5 MINUTES FROM THE PROVIDER
    # cron passes at 01:04 - 1..5 minutes: IS NOT DUE
    # cron passes at 01:05 - 1..5 minutes: IS NOT DUE
    # cron passes at 01:06 - 1..5 minutes: IS NOT DUE
    # cron passes at 01:07 - 1..5 minutes: IS DUE (but it should already be handled by EveryMinuteIsDueChecker)
    # cron passes at 01:08 - 1..5 minutes: IS DUE
    # cron passes at 01:09 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
    # cron passes at 01:10 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
    # cron passes at 01:11 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
    # cron passes at 01:12 - 1..5 minutes: IS DUE #should not if another has started during the threshold period
    # cron passes at 01:13 - 1..5 minutes: IS NOT DUE
    Synolia\SyliusSchedulerCommandPlugin\Checker\SoftLimitThresholdIsDueChecker:
        tags:
            - { name: !php/const Synolia\SyliusSchedulerCommandPlugin\Checker\IsDueCheckerInterface::TAG_ID }
        #optionnal, default value is 5 minutes
        arguments:
            $threshold: 5 #soft limit threshold in minutes

Development

See How to contribute.

License

This library is under the MIT license.

Credits

Developed by Synolia.

syliusschedulercommandplugin's People

Contributors

galloisluca avatar hugfes avatar jibbarth avatar laiah avatar lruozzi9 avatar maxperei avatar oallain avatar reyostallenberg avatar thegrimmchester 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

Watchers

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

syliusschedulercommandplugin's Issues

[Feature] Translate human readable cron expression

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I would realy love to see values in the human_readable_expression (Humanized expression) column also being translated.

Describe the solution you'd like
Use another library, like e.g. https://github.com/lorisleiva/cron-translator in ScheduledCommandHumanReadableExpressionType as that supports translations, I could make a PR for you to implement this and I could make a PR on that library so it also supports Dutch (nl).

Describe alternatives you've considered

Additional context

purge-history Command

Hi,

I would like to purge the history however when I try to run the symfony command I get this message as a response.

php bin/console synolia:scheduler:purge-history --all

**There are no commands defined in the "synolia:scheduler" namespace.

Did you mean this?
synolia**

Do I have to activate something in the configuration?
I'm on Sylius 1.10.7
Thanks

[Feature] Using the Symfony Scheduler

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
With the stable release of the Symfony Scheduler (exp. since 6.3) component right around the corner, we should keep into account that soon we will be able to use that to handle scheduling and handling of commands.

Therefore, it might be wise to already start thinking about this, when changing or adding current features to this project.
I think the Scheduler component will be able to remove a lot of code from this repo, and therefore would be the clear better choice in the future.

As a quick example, the logic used to check if a command should be scheduled to run, and when, can be condensed into this single line:

(new Schedule())->add(RecurringMessage::cron($command->getCronExpression(), new CommandMessage($command)));

If you would like any help on making this happen, let me know, and i'd love to help out with the transition

[Bug] "Live tail" not working due to missing js

Describe the bug
when I click on the log tail button, nothing happens. In console a .js script is missing. It seems related to the themes but there's no documentation about usage.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '/admin/scheduled-commands/'
  2. Click on 'See log in live'

Expected behavior
'Live view' of log file working.

Screenshots

GET http://www.foo.localhost/_themes/foo/bar/bundles/synoliasyliusschedulercommandplugin/column/index.js net::ERR_ABORTED 404

[Feature] Allow process timeout override per command

I have a long running command scheduled, which it itself runs a set of other console commands (runs a command for each channel and locale combination) and it regularly hits the 60 second time out and doesn't finish running.

I'm thinking it should be possible to pass a time out in seconds from the admin through to setTimeout() on the process, which can also take null to disable, however the Symfony docs say that for longer tasks you have to also check the timeout manually so not sure how practical that is. I also realise there might be issues if the timeout is longer than the interval between two runs of the command.

[Bug] No log file

Describe the bug
On the admin after an execution, no log file are shown.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '/admin/commands/'
  2. Setup a new task with 'execute now'
  3. No log file are shown in '/admin/scheduled-commands/'

Expected behavior
I want log file to be visible

Screenshots
image

[Feature] Timeout should be only a (signed) positive integer

Is your feature request related to a problem? Please describe.
The configurable timeout should be a positive integer only in the admin form.

Describe the solution you'd like
Add a Symfony constraint to disallow "-n" numbers.

Describe alternatives you've considered
N/A

Additional context
A customer I had with access admin to its shop has modified by mistake (mouse scroll on page scroll) the timeout and it was set to -3. Symony process crashed for days because the timeout value was invalid (obviously).

[Feature] Guide about doctrine naming_strategy

Is your feature request related to a problem? Please describe.
When I install the project, with the naming strategy doctrine.orm.naming_strategy.underscore the fields are not found due to other case being used than underscore.

Unknown column 's0_.cron_expression' in 'field list'

Describe the solution you'd like
I'm not sure what the fix should be but a note about this would be great.

[Feature] Add 24 hours format option

Is your feature request related to a problem? Please describe.
The CronExpressionHumanizer do not use the 3rd argument of translate to allow 24 hours format to be used.

Describe the solution you'd like
Maybe use an option to pass true/false.

[Bug][Security] Read and partially write any file on the server

Currently, we are able to put ANY file on the server as "log file" with relative paths. That means, we can access

Steps to reproduce the behavior:

  1. Go to 'Scheduled Commands'
  2. Click on 'Edit'
  3. Type '../../.env' as Log file
  4. Click on 'Live view', 'Clear logs' or just download the result

Expected behavior
User can't perform read/write operations on files other than logs.

[Bug] Last command not found not persited

Describe the bug
If shceduled command not fount and run at last, error code is not saved on database.

To Reproduce
Steps to reproduce the behavior:

  1. Register new sheduled command
  2. Force to have non existant command (e.g: asset:installs)
  3. Run bin/console synolia:scheduler-run
  4. Check last return code

Expected behavior
The sheduled command should have -1 as last return code

Additional context
In the case on last command, there is no flush() instruction.

[Feature] Sylius 1.11 support

Is your feature request related to a problem? Please describe.
Hello, all in the title, do you plan to support Sylius 1.11 anytime soon ?

[Bug] Warning: Attempt to read property "namespaces" on null

Composer infos

sylius/calendar        v0.3.0  Date handling for PHP applications.
sylius/fixtures-bundle v1.7.0  Configurable fixtures for Symfony applications.
sylius/grid-bundle     v1.10.2 Amazing grids with support of filters and custom fields integrated into Symfony.
sylius/mailer-bundle   v1.6.0  Mailers and e-mail template management for Symfony projects.
sylius/paypal-plugin   v1.4.1  PayPal plugin for Sylius.
sylius/registry        v1.6.0  Services registry.
sylius/resource-bundle v1.8.4  Resource component for Sylius.
sylius/sylius          v1.11.4 E-Commerce platform for PHP, based on Symfony framework.
sylius/theme-bundle    v2.2.0  Themes management for Symfony projects.

synolia/sylius-scheduler-command-plugin v3.1.0 Scheduler Command Plugin.

Describe the bug
Try to click on "New"

To Reproduce
Steps to reproduce the behavior:

  1. click "Create"

Screenshots

ErrorException:
Warning: Attempt to read property "namespaces" on null
  at C:\wamp\www\sylius\Sylius-Standard\vendor\synolia\sylius-scheduler-command-plugin\src\Parser\CommandParser.php:63

image

Additional context
Add any other context about the problem here.

Create an index for the 'state' field of the 'synolia_scheduled_commands' table

I'm getting slow queries report from Mysql because of the lack of an index for the "state" field.

The query that is reported is the following:

SELECT t0.id AS id_1, t0.name AS name_2, t0.command AS command_3, t0.arguments AS arguments_4, t0.executed_at AS executed_at_5, t0.last_return_code AS last_return_code_6, t0.log_file AS log_file_7, t0.command_end_time AS command_end_time_8, t0.created_at AS created_at_9, t0.state AS state_10, t0.timeout AS timeout_11, t0.idle_timeout AS idle_timeout_12, t0.owner_id AS owner_id_13 FROM synolia_scheduled_commands t0 WHERE t0.state = 'waiting';

Thank you!

[Feature] give possibility to run multiple instances on one server

Is your feature request related to a problem? Please describe.
I have two websites hosted on the same server. I can't run twho schedulers

Describe the solution you'd like
In this file vendor/synolia/sylius-scheduler-command-plugin/src/Command/SynoliaSchedulerRunCommand.php
replace
if (!$this->lock() {
by
if (!$this->lock(realpath(dirname(FILE)))) {

[Bug] 0 * * * * execute every minute

Describe the bug
I have set a task that would normally execute every hours: 0 * * * *

Except it runs every minutes if I look at the history of scheduled commands ?

To Reproduce
Setup a task 0 * * * * and go to admin/scheduled-commands/

Expected behavior
Run every hours at m + 0.

Screenshots
Capture d’écran de 2023-05-25 16-57-37
Capture d’écran de 2023-05-25 16-57-19

Additional context
N/A

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.