Skip to content
Snippets Groups Projects
Select Git revision
  • 7095770b9517987989e952739961475ffe97b2cc
  • master default protected
  • v1.1.0
  • v1.0.1
  • v1.0.0
5 results

WatchCommand.php

Blame
  • Dillenn Terumalai's avatar
    Dillenn Terumalai authored
    7095770b
    History
    WatchCommand.php 3.19 KiB
    <?php
    
    namespace Dterumal\Watcher\Console;
    
    use Dterumal\Watcher\Events\WatcherCreated;
    use Dterumal\Watcher\Watcher;
    use Dterumal\Watcher\WatcherOptions;
    use Illuminate\Console\Command;
    use Illuminate\Contracts\Cache\Repository;
    use Illuminate\Contracts\Cache\Repository as Cache;
    
    class WatchCommand extends Command
    {
        /**
         * The name and signature of the console command.
         *
         * @var string
         */
        protected $signature = 'watch:run
                                {--force : Force the worker to run even in maintenance mode}
                                {--once : Specify if the watcher should stop after one file has been detected}
                                {--sleep=3 : Number of seconds to sleep when no job is available}
                                {--rest=0 : Number of seconds to rest between jobs}
                                {--timeout=0 : Only process the event on the queue}';
    
        /**
         * The console command description.
         *
         * @var string
         */
        protected $description = 'Start monitoring the SFTP folder and its sub-directories for new files';
    
        /**
         * The cache store implementation.
         *
         * @var Repository
         */
        protected Repository $cache;
    
        /**
         * The inotify instance
         *
         * @var Watcher
         */
        protected Watcher $watcher;
    
        /**
         * Create a new queue restart command.
         *
         * @param  Watcher  $watcher
         * @param  Cache  $cache
         */
        public function __construct(Watcher $watcher, Cache $cache)
        {
            parent::__construct();
    
            $this->cache = $cache;
            $this->watcher = $watcher;
        }
    
        /**
         * Execute the console command.
         *
         * @return int|null
         */
        public function handle()
        {
            if ($this->downForMaintenance()) {
                $this->watcher->sleep($this->option('sleep'));
            }