Skip to content

Commit 7a54ed6

Browse files
authored
Use Storage facade instead of php file functions (#267)
* Use storage facade * Account for start not defined
1 parent 596452d commit 7a54ed6

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/Events/Executed.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Studio\Totem\Events;
44

5+
use Illuminate\Support\Facades\Storage;
56
use Studio\Totem\Notifications\TaskCompleted;
67
use Studio\Totem\Task;
78

@@ -19,15 +20,15 @@ public function __construct(Task $task, $started)
1920

2021
$time_elapsed_secs = microtime(true) - $started;
2122

22-
if (file_exists(storage_path($task->getMutexName()))) {
23-
$output = file_get_contents(storage_path($task->getMutexName()));
23+
if (Storage::exists(storage_path($task->getMutexName()))) {
24+
$output = Storage::get(storage_path($task->getMutexName()));
2425

2526
$task->results()->create([
2627
'duration' => $time_elapsed_secs * 1000,
2728
'result' => $output,
2829
]);
2930

30-
unlink(storage_path($task->getMutexName()));
31+
Storage::delete(storage_path($task->getMutexName()));
3132

3233
$task->notify(new TaskCompleted($output));
3334
$task->autoCleanup();

src/Providers/ConsoleServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function schedule(Schedule $schedule)
4141
Executing::dispatch($task);
4242
})
4343
->after(function () use ($event, $task) {
44-
Executed::dispatch($task, $event->start);
44+
Executed::dispatch($task, $event->start ?? microtime(true));
4545
})
4646
->sendOutputTo(storage_path($task->getMutexName()));
4747
if ($task->dont_overlap) {

src/Repositories/EloquentTaskRepository.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Arr;
77
use Illuminate\Support\Facades\Artisan;
88
use Illuminate\Support\Facades\Cache;
9+
use Illuminate\Support\Facades\Storage;
910
use Studio\Totem\Contracts\TaskInterface;
1011
use Studio\Totem\Events\Activated;
1112
use Studio\Totem\Events\Created;
@@ -195,9 +196,9 @@ public function execute($id)
195196
try {
196197
Artisan::call($task->command, $task->compileParameters());
197198

198-
file_put_contents(storage_path($task->getMutexName()), Artisan::output());
199+
Storage::put(storage_path($task->getMutexName()), Artisan::output());
199200
} catch (\Exception $e) {
200-
file_put_contents(storage_path($task->getMutexName()), $e->getMessage());
201+
Storage::put(storage_path($task->getMutexName()), $e->getMessage());
201202
}
202203

203204
Executed::dispatch($task, $start);

0 commit comments

Comments
 (0)