Register the Horizon job events.

@return void
328111
protected function registerEvents()
    {
        $events = $this->app->make(Dispatcher::class);

        foreach ($this->events as $event => $listeners) {
            foreach ($listeners as $listener) {
                $events->listen($event, $listener);
            }
        }
    }
1272029
protected function job(): void
    {
        $balances = $this->retrieve([
            'corporation_id' => $this->getCorporationId(),
        ]);

        if ($balances->isCachedLoad()) return;

        collect($balances)->each(function ($balance) {

            CorporationWalletBalance::firstOrNew([
                'corporation_id' => $this->getCorporationId(),
                'division'       => $balance->division,
            ])->fill([
                'balance' => $balance->balance,
            ])->save();

        });
    }
621941
public function init()
    {
        $job = $this->job = new \PHPDaemon\Core\ComplexJob(function ($job) {
            // called when job is done

            // prevent cleaning up results
            $job->keep();

            // wake up the request immediately
            $this->wakeup();
        });

        // just pushing something
        $this->appInstance->redis->lpush('mylist', microtime(true));

        // registering job named 'testquery'
        $job('testquery', function ($name, $job) {
            $this->appInstance->redis->lrange('mylist', 0, 10, function ($conn) use ($name, $job) {
                // calling lrange Redis command

                // setting job result
                $job->setResult($name, $conn->result);

            });
        });

        // let the fun begin
        $job();

        // setting timeout
        $this->sleep(1, true);
    }
5887
protected function registerQueueWorker()
    {
        $this->app->singleton('queue.worker', function () {
            if ($this->eye->laravelVersionIs('>=', '5.3.0')) {
                return new Worker($this->app['queue'], $this->app['events'], $this->app[ExceptionHandler::class]);
            } else {
                return new WorkerLegacy($this->app['queue'], $this->app['queue.failer'], $this->app['events']);
            }
        });
    }
1304040
protected function job(): void
    {
        $members = $this->retrieve([
            'corporation_id' => $this->getCorporationId(),
        ]);

        if ($members->isCachedLoad()) return;

        collect($members)->each(function ($member) {

            CorporationMemberTracking::firstOrNew([
                'corporation_id' => $this->getCorporationId(),
                'character_id'   => $member->character_id,
            ])->fill([
                'start_date'   => property_exists($member, 'start_date') ?
                    carbon($member->start_date) : null,
                'base_id'      => $member->base_id ?? null,
                'logon_date'   => property_exists($member, 'logon_date') ?
                    carbon($member->logon_date) : null,
                'logoff_date'  => property_exists($member, 'logoff_date') ?
                    carbon($member->logoff_date) : null,
                'location_id'  => $member->location_id ?? null,
                'ship_type_id' => $member->ship_type_id ?? null,
            ])->save();
        });

        CorporationMemberTracking::where('corporation_id', $this->getCorporationId())
            ->whereNotIn('character_id', collect($members)->pluck('character_id')->all())
            ->delete();
    }
299545
protected function job(): void
    {
        $empty_contracts = CorporationContract::join('contract_details',
            'corporation_contracts.contract_id', '=',
            'contract_details.contract_id')
            ->where('corporation_id', $this->getCorporationId())
            ->where('type', '<>', 'courier')
            ->where('status', '<>', 'deleted')
            ->where('volume', '>', 0)
            ->whereNotIn('corporation_contracts.contract_id', function ($query) {

                $query->select('contract_id')
                    ->distinct()
                    ->from((new ContractItem)->getTable());

            })
            ->pluck('corporation_contracts.contract_id');

        $empty_contracts->each(function ($contract_id) {

            $this->iteration_count++;

            try {
                $items = $this->retrieve([
                    'corporation_id' => $this->getCorporationId(),
                    'contract_id' => $contract_id,
                ]);

                if ($items->isCachedLoad()) return;

                collect($items)->each(function ($item) use ($contract_id) {

                    ContractItem::upsert([
                        'contract_id' => $contract_id,
                        'record_id' => $item->record_id,
                        'type_id' => $item->type_id,
                        'quantity' => $item->quantity,
                        'raw_quantity' => $item->raw_quantity ?? null,
                        'is_singleton' => $item->is_singleton,
                        'is_included' => $item->is_included,
                    ], [
                        'contract_id', 'record_id',
                    ]);
                });

                // Check if we should be stopping this job all together.
                // The next time a job is queued it will just continue
                // where it left off.
                if ($this->job_start_time->copy()->addSeconds($this->max_job_runtime) < carbon('now'))
                    return false;

                // Check if we should be sleeping. This should be true if we
                // have made 20 requests in the last 10 seconds.
                // If the time we started, plus 10 seconds is more than the current
                // time, wait for the remainder of the time.
                if ($this->iteration_count >= $this->max_cycle_requests &&
                    $this->cycle_start_time->copy()->addSeconds($this->cycle_duration) < carbon('now')) {

                    $wait_duration = $this->cycle_start_time->copy()->addSeconds($this->cycle_duration)
                        ->diffInSeconds(carbon('now'));

                    sleep($wait_duration);

                    // Reset the cycle start time as well as the iteration count.
                    $this->cycle_start_time = carbon('now');
                    $this->iteration_count = 0;
                }

                // Check if we should just reset the iteration & cycle count as a result of
                // us not using the full 20 requests in a 10 second window.
                if ($this->cycle_start_time->copy()->addSeconds($this->cycle_duration) < carbon('now')) {

                    $this->cycle_start_time = carbon('now');
                    $this->iteration_count = 0;

                }
            } catch (RequestFailedException $e) {
                if (strtolower($e->getError()) == 'contract not found!') {
                    ContractDetail::where('contract_id', $contract_id)
                                  ->update([
                                      'status' => 'deleted',
                                  ]);

                    return;
                }

                throw $e;
            }
        });
    }
1166244
public function registerProfilerQueryEvent()
	{
		$app = $this->app;

		$app['events']->listen('illuminate.query', function($query, $bindings, $time, $connectionName) use ($app)
		{
			// Don't log the query if the profiler is disabled.
			if($app['profiler']->isEnabled())
			{
				// If the query had some bindings we'll need to add those back
				// into the query.
				if( ! empty($bindings))
				{
					// Let's grab the query's connection. We will use it to prepare and then quote
					// the bindings before they are inserted back into the query.
					$connection = $app['db']->connection($connectionName);
					$pdo = $connection->getPdo();

					$bindings = $connection->prepareBindings($bindings);

					// Let's loop add each binding back into the original query, one binding
					// at a time.
					foreach($bindings as $binding)
					{
						$query = preg_replace('/\?/', $pdo->quote($binding), $query, 1);
					}
				}

				$app['profiler']->log->query($query, $time);
			}
		});
	}
858506
protected function job(): void
    {
        while (true) {

            $industry_jobs = $this->retrieve([
                'corporation_id' => $this->getCorporationId(),
            ]);

            if ($industry_jobs->isCachedLoad()) return;

            collect($industry_jobs)->each(function ($job) {

                CorporationIndustryJob::firstOrNew([
                    'corporation_id' => $this->getCorporationId(),
                    'job_id'         => $job->job_id,
                ])->fill([
                    'installer_id'           => $job->installer_id,
                    'facility_id'            => $job->facility_id,
                    'location_id'            => $job->location_id,
                    'activity_id'            => $job->activity_id,
                    'blueprint_id'           => $job->blueprint_id,
                    'blueprint_type_id'      => $job->blueprint_type_id,
                    'blueprint_location_id'  => $job->blueprint_location_id,
                    'output_location_id'     => $job->output_location_id,
                    'runs'                   => $job->runs,
                    'cost'                   => $job->cost ?? null,
                    'licensed_runs'          => $job->licensed_runs ?? null,
                    'probability'            => $job->probability ?? null,
                    'product_type_id'        => $job->product_type_id ?? null,
                    'status'                 => $job->status,
                    'duration'               => $job->duration,
                    'start_date'             => carbon($job->start_date),
                    'end_date'               => carbon($job->end_date),
                    'pause_date'             => property_exists($job, 'pause_date') ?
                        carbon($job->pause_date) : null,
                    'completed_date'         => property_exists($job, 'completed_date') ?
                        carbon($job->completed_date) : null,
                    'completed_character_id' => $job->completed_character_id ?? null,
                    'successful_runs'        => $job->successful_runs ?? null,
                ])->save();
            });

            if (! $this->nextPage($industry_jobs->pages))
                return;
        }
    }
658122
protected function job(): void
    {
        CorporationIndustryMiningObserver::where('corporation_id', $this->getCorporationId())
            ->get()->each(function ($observer) {

                while (true) {

                    $detail = $this->retrieve([
                        'corporation_id' => $this->getCorporationId(),
                        'observer_id'    => $observer->observer_id,
                    ]);

                    if ($detail->isCachedLoad()) return;

                    collect($detail)->each(function ($data) use ($observer) {

                        CorporationIndustryMiningObserverData::firstOrNew([
                            'corporation_id'          => $this->getCorporationId(),
                            'observer_id'             => $observer->observer_id,
                            'recorded_corporation_id' => $data->recorded_corporation_id,
                            'character_id'            => $data->character_id,
                            'type_id'                 => $data->type_id,
                            'last_updated'            => $data->last_updated,
                        ])->fill([
                            'quantity' => $data->quantity,
                        ])->save();

                    });

                    if (! $this->nextPage($detail->pages))
                        break;

                }

                $this->page = 1;
            });
    }
23715
public function register()
    {
        $this->app['events']->listen(JobProcessing::class, function () {
            $connection = $this->app['config']->get('queue.failed.connection', null);
            $tableName  = $this->app['config']->get('queue.failed.table', 'failed_jobs');

            $schema = $this->app['registry']
                ->getConnection($connection)
                ->getSchemaManager();

            if (!$schema->tablesExist($tableName)) {
                $schema->createTable(
                    (new FailedJobTable($tableName))->build()
                );
            }
        });
    }
511233
protected function registerWorker()
    {
        $this->app->singleton('queue.worker', function () {
            return new Worker(
                $this->app['queue'], $this->app['events'], $this->app[ExceptionHandler::class]
            );
        });
    }
295344
protected function job(): void
    {
        $corporation = $this->retrieve([
            'corporation_id' => $this->getCorporationId(),
        ]);

        if ($corporation->isCachedLoad()) return;

        CorporationInfo::firstOrNew([
            'corporation_id' => $this->getCorporationId(),
        ])->fill([
            'name'            => $corporation->name,
            'ticker'          => $corporation->ticker,
            'member_count'    => $corporation->member_count,
            'ceo_id'          => $corporation->ceo_id,
            'alliance_id'     => $corporation->alliance_id ?? null,
            'description'     => $corporation->description ?? null,
            'tax_rate'        => $corporation->tax_rate,
            'date_founded'    => property_exists($corporation, 'date_founded') ?
                carbon($corporation->date_founded) : null,
            'creator_id'      => $corporation->creator_id,
            'url'             => $corporation->url ?? null,
            'faction_id'      => $corporation->faction_id ?? null,
            'home_station_id' => $corporation->home_station_id ?? null,
            'shares'          => $corporation->shares ?? null,
        ])->save();
    }
286005
protected function registerManagerStopCallback()
    {
        $this->swooleServer->on('ManagerStop', function () {
            $this->events->dispatch(new Events\ManagerStopped($this));

            $this->dispatchEvent('ManagerStop', $this);
        });
    }
1054842
private function addJobs()
    {
        foreach ($this->cronjobs as $jobName => $jobConfig) {
            $this->addJob($jobName, $jobConfig);
        }
    }
70191
protected function registerWorkerStartCallback()
    {
        $this->swooleServer->on('WorkerStart', function ($server, $workerId) {
            $this->setProcessName(sprintf(
                '%s : Worker %d%s', $this->app->name(), $workerId, $server->taskworker ? ' Task' : ''
            ));

            $this->events->dispatch(new Events\WorkerStarted($this, $workerId));

            $this->dispatchEvent('WorkerStart', $this, $workerId);
        });
    }
530336
public function register_cron() {
		if ( ! wp_next_scheduled( $this->event ) ) {
			wp_schedule_event( $this->start_at(), $this->schedule, $this->event, $this->args() );
		}
		add_action( $this->event, [ $this, 'process' ] );
	}
1078065
public function bootAfterAll(): void
    {
        /** @var QueueManager $queue */
        $queue = app('queue');

        // Add database Connector
        $queue->addConnector('database', function () {
            return new DatabaseConnector($this->app['db']);
        });

        // Add RabbitMq Connector
        if (!empty($this->app->getProviders('VladimirYuldashev\LaravelQueueRabbitMQ\LaravelQueueRabbitMQServiceProvider'))) {
            $queue->addConnector('rabbitmq', function () {
                return new RabbitMQConnector($this->app['events']);
            });
        }

        if (!empty($this->app->getProviders('Laravel\Horizon\HorizonServiceProvider'))) {
            // Add horizon Connector
            $queue->addConnector('redis', function () {
                return new HorizonConnector($this->app['redis']);
            });
        } else {
            // Add Redis Connector
            $queue->addConnector('redis', function () {
                return new RedisConnector($this->app['redis']);
            });
        }
    }