forked from tradecoverexchange/google-cloud-tasks-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCloudTaskServiceProvider.php
70 lines (60 loc) · 2.44 KB
/
CloudTaskServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace TradeCoverExchange\GoogleCloudTaskLaravel;
use Illuminate\Queue\QueueManager;
use Illuminate\Queue\Worker;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use TradeCoverExchange\GoogleCloudTaskLaravel\Controllers\CloudTasksController;
use TradeCoverExchange\GoogleCloudTaskLaravel\Middlewares\CloudTasks;
use TradeCoverExchange\GoogleCloudTaskLaravel\Middlewares\ConfigureUrlGenerator;
class CloudTaskServiceProvider extends ServiceProvider
{
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->publishes(
[
__DIR__ . '/../config/queue.php' => config_path('queue.php'),
],
'cloud-task-config'
);
$this->commands([
Commands\CreateQueueCommand::class,
Commands\DeleteQueueCommand::class,
Commands\PurgeQueueCommand::class,
Commands\QueueStatusCommand::class,
Commands\QueueStatsCommand::class,
Commands\UpdateQueueCommand::class,
Commands\ListTasksCommand::class,
]);
}
$this->mapRoutes();
}
public function register(): void
{
$this->app->when(CloudTasksController::class)
->needs(Worker::class)
->give(function () {
return $this->app->make('queue.worker');
});
$this->app->scoped(GoogleCloudTasks::class);
// Queue Factory extension used to make the package compatible with other packages
// which might try to access the factory before the boot method of this service
// provider has been called.
$this->app->extend(QueueManager::class, function (QueueManager $queueManager) {
$queueManager->extend(Connectors\AppEngineConnector::DRIVER, function () {
return $this->app->make(Connectors\AppEngineConnector::class);
});
$queueManager->extend(Connectors\CloudTasksConnector::DRIVER, function () {
return $this->app->make(Connectors\CloudTasksConnector::class);
});
return $queueManager;
});
}
protected function mapRoutes()
{
Route::post('/_googleTasks/{connection}/{queue}', CloudTasksController::class)
->name('google.tasks')
->middleware([CloudTasks::class, ConfigureUrlGenerator::class]);
}
}