Skip to content

Commit

Permalink
Use Storage facade instead of php file functions (codestudiohq#267)
Browse files Browse the repository at this point in the history
* Use storage facade

* Account for start not defined
  • Loading branch information
lucidlogic authored Jan 20, 2021
1 parent 596452d commit 7a54ed6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/Events/Executed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Studio\Totem\Events;

use Illuminate\Support\Facades\Storage;
use Studio\Totem\Notifications\TaskCompleted;
use Studio\Totem\Task;

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

$time_elapsed_secs = microtime(true) - $started;

if (file_exists(storage_path($task->getMutexName()))) {
$output = file_get_contents(storage_path($task->getMutexName()));
if (Storage::exists(storage_path($task->getMutexName()))) {
$output = Storage::get(storage_path($task->getMutexName()));

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

unlink(storage_path($task->getMutexName()));
Storage::delete(storage_path($task->getMutexName()));

$task->notify(new TaskCompleted($output));
$task->autoCleanup();
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/ConsoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function schedule(Schedule $schedule)
Executing::dispatch($task);
})
->after(function () use ($event, $task) {
Executed::dispatch($task, $event->start);
Executed::dispatch($task, $event->start ?? microtime(true));
})
->sendOutputTo(storage_path($task->getMutexName()));
if ($task->dont_overlap) {
Expand Down
5 changes: 3 additions & 2 deletions src/Repositories/EloquentTaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Studio\Totem\Contracts\TaskInterface;
use Studio\Totem\Events\Activated;
use Studio\Totem\Events\Created;
Expand Down Expand Up @@ -195,9 +196,9 @@ public function execute($id)
try {
Artisan::call($task->command, $task->compileParameters());

file_put_contents(storage_path($task->getMutexName()), Artisan::output());
Storage::put(storage_path($task->getMutexName()), Artisan::output());
} catch (\Exception $e) {
file_put_contents(storage_path($task->getMutexName()), $e->getMessage());
Storage::put(storage_path($task->getMutexName()), $e->getMessage());
}

Executed::dispatch($task, $start);
Expand Down

0 comments on commit 7a54ed6

Please sign in to comment.