Code Monkey home page Code Monkey logo

tasks's Introduction

CodeIgniter 4 Development

PHPUnit PHPStan Psalm Coverage Status Downloads GitHub release (latest by date) GitHub stars GitHub license contributions welcome

What is CodeIgniter?

CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure. More information can be found at the official site.

This repository holds the source code for CodeIgniter 4 only. Version 4 is a complete rewrite to bring the quality and the code into a more modern version, while still keeping as many of the things intact that has made people love the framework over the years.

More information about the plans for version 4 can be found in CodeIgniter 4 on the forums.

Documentation

The User Guide is the primary documentation for CodeIgniter 4.

You will also find the current in-progress User Guide. As with the rest of the framework, it is a work in progress, and will see changes over time to structure, explanations, etc.

You might also be interested in the API documentation for the framework components.

Important Change with index.php

index.php is no longer in the root of the project! It has been moved inside the public folder, for better security and separation of components.

This means that you should configure your web server to "point" to your project's public folder, and not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter public/..., as the rest of your logic and the framework are exposed.

Please read the user guide for a better explanation of how CI4 works!

Repository Management

CodeIgniter is developed completely on a volunteer basis. As such, please give up to 7 days for your issues to be reviewed. If you haven't heard from one of the team in that time period, feel free to leave a comment on the issue so that it gets brought back to our attention.

Important

We use GitHub issues to track BUGS and to track approved DEVELOPMENT work packages. We use our forum to provide SUPPORT and to discuss FEATURE REQUESTS.

If you raise an issue here that pertains to support or a feature request, it will be closed! If you are not sure if you have found a bug, raise a thread on the forum first - someone else may have encountered the same thing.

Before raising a new GitHub issue, please check that your bug hasn't already been reported or fixed.

We use pull requests (PRs) for CONTRIBUTIONS to the repository. We are looking for contributions that address one of the reported bugs or approved work packages.

Do not use a PR as a form of feature request. Unsolicited contributions will only be considered if they fit nicely into the framework roadmap. Remember that some components that were part of CodeIgniter 3 are being moved to optional packages, with their own repository.

Contributing

We are accepting contributions from the community! It doesn't matter whether you can code, write documentation, or help find bugs, all contributions are welcome.

Please read the Contributing to CodeIgniter.

CodeIgniter has had thousands on contributions from people since its creation. This project would not be what it is without them.

Made with contrib.rocks.

Server Requirements

PHP version 8.1 or higher is required, with the following extensions installed:

Warning

The end of life date for PHP 7.4 was November 28, 2022. The end of life date for PHP 8.0 was November 26, 2023. If you are still using PHP 7.4 or 8.0, you should upgrade immediately. The end of life date for PHP 8.1 will be November 25, 2024.

Additionally, make sure that the following extensions are enabled in your PHP:

  • json (enabled by default - don't turn it off)
  • mysqlnd if you plan to use MySQL
  • libcurl if you plan to use the HTTP\CURLRequest library

Running CodeIgniter Tests

Information on running the CodeIgniter test suite can be found in the README.md file in the tests directory.

tasks's People

Contributors

chompi0 avatar colethorsen avatar datamweb avatar ddevsr avatar dependabot[bot] avatar kenjis avatar kloukas avatar lonnieezell avatar mgatner avatar michalsn avatar muhannad17 avatar samsonasik 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

Watchers

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

tasks's Issues

codeigniter4/tasks missing in packagists

I tried to use this library using composer require codeigniter4/tasks just like the docs say, but it returned the error below:

./composer.json has been updated
Running composer update codeigniter4/tasks
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires codeigniter4/tasks, it could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it  

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Upon troubleshooting, I realised that the package doesn't exist in packagist.org:

image

Is this an oversight?

Infection fails when merging

Run git fetch --depth=1 origin $GITHUB_BASE_REF
  git fetch --depth=1 origin $GITHUB_BASE_REF
  infection --threads=2 --skip-initial-tests --coverage=build/phpunit --git-diff-base=origin/$GITHUB_BASE_REF --git-diff-filter=AM --logger-github --ignore-msi-with-no-mutations
  shell: /usr/bin/bash -e {0}
  env:
    COMPOSER_PROCESS_TIMEOUT: 0
    COMPOSER_NO_INTERACTION: 1
    COMPOSER_NO_AUDIT: 1
    COMPOSER_AUTH: {"github-oauth": {"github.com": "***"}}
    COMPOSER_CACHE_FILES_DIR: /home/runner/.cache/composer/files

In Process.php line 112:
                                                                               
  The command "'git' 'diff' 'origin/' '--diff-filter' 'AM' '--name-only' '--'  
   'src/'" failed.                                                             
                                                                               
  Exit Code: 128(Invalid exit argument)                                        
                                                                               
  Working directory: /home/runner/work/tasks/tasks                             
                                                                               
  Output:                                                                      
  ================                                                             
                                                                               
                                                                               
  Error Output:                                                                
  ================                                                             
  fatal: bad revision 'origin/'                                                
                                                                               

run [--test-framework TEST-FRAMEWORK] [--test-framework-options TEST-FRAMEWORK-OPTIONS] [-j|--threads THREADS] [--only-covered] [-s|--show-mutations] [--no-progress] [--force-progress] [-c|--configuration CONFIGURATION] [--coverage COVERAGE] [--mutators MUTATORS] [--filter FILTER] [--formatter FORMATTER] [--git-diff-filter GIT-DIFF-FILTER] [--git-diff-lines] [--git-diff-base GIT-DIFF-BASE] [--logger-github [LOGGER-GITHUB]] [--logger-html LOGGER-HTML] [--noop] [--only-covering-test-cases] [--min-msi MIN-MSI] [--min-covered-msi MIN-COVERED-MSI] [--log-verbosity LOG-VERBOSITY] [--initial-tests-php-options INITIAL-TESTS-PHP-OPTIONS] [--skip-initial-tests] [--ignore-msi-with-no-mutations] [--debug] [--dry-run]

Error: Process completed with exit code 1.

https://github.com/codeigniter4/tasks/actions/runs/5154794891/jobs/9283672396

CronExpression Class

The CronExpression class should be able to:

  • understand the standard cron format (* * * * *)
  • be able to check if a task should be ran based on the cron expression and the current time
  • should be able to run based upon a different timezone than the current system settings
  • should be able to list future and previous run times.

Running multiple tasks asynchronously

I take a look at what been going on here and i wonder if one thing is possible with this.

I work on a project with CI4 which relays heavily on cron to fetch the data from APIs. We're fetching data form about 30 endpoints every minute. And each of the request takes a lot of time to complete the processing. So in other to achieve those I need to spawn a lot of processes to work at the same time. So I have a single command which executed the multiple instances of other command by using something like this

/**
 * Spark Exec
 *
 * @param string   $sparkCommand Command
 * @param int|null $timeout      Timeout
 */
function spark_exec(string $sparkCommand, ?int $timeout = null): void
{
    $command = '';

    if ($timeout) {
        $command .= 'timeout ' . $timeout . ' ';
    }

    $command .= '"' . PHP_BINARY . '" -c "' . (get_cfg_var('cfg_file_path') ?: PHP_CONFIG_FILE_PATH) . '" ' . ROOTPATH . 'spark ' . $sparkCommand . ' > /dev/null &';

    exec($command);
}

And the problem is that I cannot have more that one process working working with the same endpoint and writing the same data db so I have mechanism to put some locks in place so I use files to track the locking

/**
     * Crates the Lockfile with the current class name
     *
     * @param string|null $identifier String to append to the filename
     *
     * @return bool|resource Locked file if successful otherwise false
     */
    public static function lock(?string $identifier = null)
    {
        //Add leading dash to identifier if it is set
        if (isset($identifier)) {
            $identifier = '-' . $identifier;
        }

        //Get the locks file directory
        $lockDir = WRITEPATH . 'cron/locks/';

        //Create the locks file directory if it does not exist
        if (! file_exists($lockDir)) {
            mkdir($lockDir, 0755, true);
        }

        //Get the filename
        $filename = $lockDir . $identifier . '.lock';

        //Open the file for writing to lock it
        $lock = fopen($filename, 'wb');

        if ($lock === false) {
            // Unable to open file, check that you have permissions to open/write
            CLI::error('Unable to write the lock file');

            exit;
        }

        if (flock($lock, LOCK_EX | LOCK_NB) === false) {
            // Lock is already in use by another process
            CLI::error('Another instance is already running');

            exit;
        }

        //Return the locked file
        return $lock;
    }

    /**
     * Closes the file removing the lock
     *
     * @param resource $lock Lock
     */
    public static function unlock(&$lock): void
    {
        //Check if lock exist
        if ($lock && get_resource_type($lock) !== 'Unknown') {
            //Get the filename
            $metaData = stream_get_meta_data($lock);
            $filename = $metaData['uri'];

            //Close the file to remove the lock
            fclose($lock);

            //Remove the lock file
            unlink($filename);
        }
    }

    /**
     * Check if lock files with set prefix exist
     *
     * @param string $prefix filename prefix
     *
     * @return bool Ture if there are lock files otherwise false
     */
    public static function isWorking(string $prefix): bool
    {
        $result = false;

        //We read the locks directory if there are  lock files it means we're still working
        if ($openDir = opendir(WRITEPATH . 'cron/locks/')) {
            while (($file = readdir($openDir)) !== false) {
                if (substr($file, 0, strlen($prefix)) === $prefix) {
                    $result = true;
                    break;
                }
            }
        }

        return $result;
    }

I wonder if there are plans to be able to achieve something similar with the scheduler here. From looking at the code I believe all the scheduled actions run on a single thread. So for example if I have 2 tasks scheduled to run first runs every 5 minutes second task runs every minute. And if first task takes more that 1 minute to be completed. On the next cron run second task will be started but once the first process finishes with task 1 it will continue with the second task in the first process and the order of execution is completely broken.

And there are a lot of real case situations where long running tasks are needed. One example is generating sitemap from the database for the huge site

Extending Tasks

Defining tasks solely in the Config file's init() method requires a single entry point for all scheduling. It might be good to offer a way to extend this to libraries and modules, so (for example) an Auth library could "register" its own tasks for periodic cleanup of spam accounts.

Callables

I wonder about the choice to use Closure for the "on-the-fly" task type. It seems unnecessarily restrictive over callable, however when I went to expand it this is the prohibitive piece:

        // Get a hash based on the action
        // Closures cannot be serialized so do it the hard way
        if ($this->getType() === 'closure') {
            $ref  = new \ReflectionFunction($this->getAction());
            $file = new \SplFileObject($ref->getFileName());
            $file->seek($ref->getStartLine() - 1);
            $content = '';

            while ($file->key() < $ref->getEndLine()) {
                $content .= $file->current();
                $file->next();
            }
            $actionString = json_encode([
                $content,
                $ref->getStaticVariables(),
            ]);

I assume this is just a convenient way of identifying the task - could we come up with a way to expand this to handle all callable type?

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.