File tree 7 files changed +114
-0
lines changed
7 files changed +114
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public function handle()
30
30
/**
31
31
* See: https://laravel-workflow.com/docs/features/timers
32
32
*/
33
+
33
34
$ workflow = WorkflowStub::make (ElapsedTimeWorkflow::class);
34
35
$ workflow ->start ();
35
36
while ($ workflow ->running ());
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public function handle()
30
30
/**
31
31
* See: https://laravel-workflow.com/blog/automating-qa-with-playwright-and-laravel-workflow
32
32
*/
33
+
33
34
$ workflow = WorkflowStub::make (CheckConsoleErrorsWorkflow::class);
34
35
$ workflow ->start ('https://example.com ' );
35
36
while ($ workflow ->running ());
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 6
6
7
7
return Application::configure (basePath: dirname (__DIR__ ))
8
8
->withRouting (
9
+ api: __DIR__ .'/../routes/api.php ' ,
9
10
web: __DIR__ .'/../routes/web.php ' ,
10
11
commands: __DIR__ .'/../routes/console.php ' ,
11
12
health: '/up ' ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Workflow \Webhooks ;
4
+
5
+ Webhooks::routes ();
You can’t perform that action at this time.
0 commit comments