Server IP : 127.0.0.2 / Your IP : 3.144.112.72 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/ |
Upload File : |
<?php namespace Illuminate\Queue; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Redis\Database; use Illuminate\Queue\Jobs\RedisJob; use Illuminate\Contracts\Queue\Queue as QueueContract; class RedisQueue extends Queue implements QueueContract { /** * The Redis database instance. * * @var \Illuminate\Redis\Database */ protected $redis; /** * The connection name. * * @var string */ protected $connection; /** * The name of the default queue. * * @var string */ protected $default; /** * The expiration time of a job. * * @var int|null */ protected $expire = 60; /** * Create a new Redis queue instance. * * @param \Illuminate\Redis\Database $redis * @param string $default * @param string $connection * @param int $expire * @return void */ public function __construct(Database $redis, $default = 'default', $connection = null, $expire = 60) { $this->redis = $redis; $this->expire = $expire; $this->default = $default; $this->connection = $connection; } /** * Get the size of the queue. * * @param string $queue * @return int */ public function size($queue = null) { $queue = $this->getQueue($queue); return $this->getConnection()->eval(LuaScripts::size(), 3, $queue, $queue.':delayed', $queue.':reserved'); } /** * Push a new job onto the queue. * * @param string $job * @param mixed $data * @param string $queue * @return mixed */ public function push($job, $data = '', $queue = null) { return $this->pushRaw($this->createPayload($job, $data), $queue); } /** * Push a raw payload onto the queue. * * @param string $payload * @param string $queue * @param array $options * @return mixed */ public function pushRaw($payload, $queue = null, array $options = []) { $this->getConnection()->rpush($this->getQueue($queue), $payload); return Arr::get(json_decode($payload, true), 'id'); } /** * Push a new job onto the queue after a delay. * * @param \DateTime|int $delay * @param string $job * @param mixed $data * @param string $queue * @return mixed */ public function later($delay, $job, $data = '', $queue = null) { $payload = $this->createPayload($job, $data); $this->getConnection()->zadd( $this->getQueue($queue).':delayed', $this->getTime() + $this->getSeconds($delay), $payload ); return Arr::get(json_decode($payload, true), 'id'); } /** * Pop the next job off of the queue. * * @param string $queue * @return \Illuminate\Contracts\Queue\Job|null */ public function pop($queue = null) { $original = $queue ?: $this->default; $queue = $this->getQueue($queue); $this->migrateExpiredJobs($queue.':delayed', $queue); if (! is_null($this->expire)) { $this->migrateExpiredJobs($queue.':reserved', $queue); } list($job, $reserved) = $this->getConnection()->eval( LuaScripts::pop(), 2, $queue, $queue.':reserved', $this->getTime() + $this->expire ); if ($reserved) { return new RedisJob($this->container, $this, $job, $reserved, $original); } } /** * Delete a reserved job from the queue. * * @param string $queue * @param string $job * @return void */ public function deleteReserved($queue, $job) { $this->getConnection()->zrem($this->getQueue($queue).':reserved', $job); } /** * Delete a reserved job from the reserved queue and release it. * * @param string $queue * @param string $job * @param int $delay * @return void */ public function deleteAndRelease($queue, $job, $delay) { $queue = $this->getQueue($queue); $this->getConnection()->eval( LuaScripts::release(), 2, $queue.':delayed', $queue.':reserved', $job, $this->getTime() + $delay ); } /** * Migrate the delayed jobs that are ready to the regular queue. * * @param string $from * @param string $to * @return void */ public function migrateExpiredJobs($from, $to) { $this->getConnection()->eval( LuaScripts::migrateExpiredJobs(), 2, $from, $to, $this->getTime() ); } /** * Create a payload string from the given job and data. * * @param string $job * @param mixed $data * @param string $queue * @return string */ protected function createPayload($job, $data = '', $queue = null) { $payload = $this->setMeta( parent::createPayload($job, $data), 'id', $this->getRandomId() ); return $this->setMeta($payload, 'attempts', 1); } /** * Get a random ID string. * * @return string */ protected function getRandomId() { return Str::random(32); } /** * Get the queue or return the default. * * @param string|null $queue * @return string */ protected function getQueue($queue) { return 'queues:'.($queue ?: $this->default); } /** * Get the connection for the queue. * * @return \Predis\ClientInterface */ protected function getConnection() { return $this->redis->connection($this->connection); } /** * Get the underlying Redis instance. * * @return \Illuminate\Redis\Database */ public function getRedis() { return $this->redis; } }