Skip to content

Commit 76ffec5

Browse files
committed
Upgrade to Laravel 12
1 parent a4aa24d commit 76ffec5

File tree

7 files changed

+114
-0
lines changed

7 files changed

+114
-0
lines changed

app/Console/Commands/Elapsed.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function handle()
3030
/**
3131
* See: https://laravel-workflow.com/docs/features/timers
3232
*/
33+
3334
$workflow = WorkflowStub::make(ElapsedTimeWorkflow::class);
3435
$workflow->start();
3536
while ($workflow->running());

app/Console/Commands/Playwright.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function handle()
3030
/**
3131
* See: https://laravel-workflow.com/blog/automating-qa-with-playwright-and-laravel-workflow
3232
*/
33+
3334
$workflow = WorkflowStub::make(CheckConsoleErrorsWorkflow::class);
3435
$workflow->start('https://example.com');
3536
while ($workflow->running());

app/Console/Commands/Webhook.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Http;
7+
use Workflow\Models\StoredWorkflow;
8+
use Workflow\WorkflowStub;
9+
10+
class Webhook extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'app:webhook';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Runs a workflow via a webhook and then signals it';
25+
26+
/**
27+
* Execute the console command.
28+
*/
29+
public function handle()
30+
{
31+
/**
32+
* See: https://laravel-workflow.com/docs/features/webhooks
33+
*/
34+
35+
$workflowCount = StoredWorkflow::count();
36+
37+
Http::post('http://localhost/api/webhooks/start/webhook-workflow', [
38+
'message' => 'world',
39+
]);
40+
41+
$id = StoredWorkflow::count();
42+
43+
if ($workflowCount === $id) {
44+
$this->error('Workflow did not start');
45+
return;
46+
}
47+
48+
Http::post("http://localhost/api/webhooks/signal/webhook-workflow/{$id}/ready");
49+
50+
$workflow = WorkflowStub::load($id);
51+
while ($workflow->running());
52+
$this->info($workflow->output());
53+
}
54+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Workflows\Webhooks;
6+
7+
use Workflow\Activity;
8+
9+
class WebhookActivity extends Activity
10+
{
11+
public function execute($message)
12+
{
13+
return 'Hello ' . $message;
14+
}
15+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Workflows\Webhooks;
6+
7+
use Workflow\ActivityStub;
8+
use Workflow\SignalMethod;
9+
use Workflow\Webhook;
10+
use Workflow\Workflow;
11+
use Workflow\WorkflowStub;
12+
13+
/**
14+
* See: https://laravel-workflow.com/docs/features/webhooks
15+
*/
16+
17+
#[Webhook]
18+
class WebhookWorkflow extends Workflow
19+
{
20+
public bool $ready = false;
21+
22+
#[SignalMethod]
23+
#[Webhook]
24+
public function ready()
25+
{
26+
$this->ready = true;
27+
}
28+
29+
public function execute($message)
30+
{
31+
WorkflowStub::await(fn () => $this->ready);
32+
33+
$result = yield ActivityStub::make(WebhookActivity::class, $message);
34+
35+
return $result;
36+
}
37+
}

bootstrap/app.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
return Application::configure(basePath: dirname(__DIR__))
88
->withRouting(
9+
api: __DIR__.'/../routes/api.php',
910
web: __DIR__.'/../routes/web.php',
1011
commands: __DIR__.'/../routes/console.php',
1112
health: '/up',

routes/api.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
use Workflow\Webhooks;
4+
5+
Webhooks::routes();

0 commit comments

Comments
 (0)