File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed
Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -104,10 +104,18 @@ class GetFile extends Task
104104}
105105```
106106
107+ Blade template:
108+
107109``` blade
108110cat {{ $options() }} {{ $path }}
109111```
110112
113+ You can create a new instance of the Task using the static ` make() ` method:
114+
115+ ``` php
116+ GetFile::make('/etc/hosts')->dispatch();
117+ ```
118+
111119## Task options
112120
113121You may specify a timeout. By default, the timeout is based on the ` task-runner.default_timeout ` config value.
Original file line number Diff line number Diff line change @@ -156,11 +156,21 @@ public function pending(): PendingTask
156156 return new PendingTask ($ this );
157157 }
158158
159+ /**
160+ * Returns a new PendingTask with this task.
161+ *
162+ * @return \ProtoneMedia\LaravelTaskRunner\PendingTask
163+ */
164+ public static function make (...$ arguments ): PendingTask
165+ {
166+ return (new static (...$ arguments ))->pending ();
167+ }
168+
159169 /**
160170 * Helper methods to create a new PendingTask.
161171 */
162172 public static function __callStatic ($ name , $ arguments )
163173 {
164- return app ( static ::class )->pending ()->{$ name }(...$ arguments );
174+ return ( new static )->pending ()->{$ name }(...$ arguments );
165175 }
166176}
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ class CustomTask extends Task
1414
1515 public $ someData = 'foo ' ;
1616
17+ public function __construct ($ someData = 'foo ' )
18+ {
19+ $ this ->someData = $ someData ;
20+ }
21+
1722 public function someMethod ()
1823 {
1924 return 'bar ' ;
Original file line number Diff line number Diff line change 55use Illuminate \Support \Facades \View ;
66use Mockery ;
77use ProtoneMedia \LaravelTaskRunner \Connection ;
8+ use ProtoneMedia \LaravelTaskRunner \PendingTask ;
89
910it ('can generate defaults based on the class name and configuration ' , function () {
1011 $ task = new DemoTask ;
6061 expect ($ task ->getScript ())->toBe ('baz foo bar ' );
6162});
6263
64+ it ('has a helper method to create the task fluently ' , function () {
65+ $ task = CustomTask::make ('otherData ' );
66+
67+ expect ($ task )->toBeInstanceOf (PendingTask::class);
68+ expect ($ task ->task ->someData )->toBe ('otherData ' );
69+ });
70+
6371it ('can create a pending task with a static method ' , function () {
6472 $ pendingTask = DemoTask::inBackground ();
6573 expect ($ pendingTask ->task )->toBeInstanceOf (DemoTask::class);
You can’t perform that action at this time.
0 commit comments