Skip to content

Commit 93861f7

Browse files
authored
Replace use of storage logs by passing output to events (#298)
1 parent d66d29c commit 93861f7

File tree

5 files changed

+13
-40
lines changed

5 files changed

+13
-40
lines changed

config/totem.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,4 @@
234234
'enabled' => env('TOTEM_BROADCASTING_ENABLED', true),
235235
'channel' => env('TOTEM_BROADCASTING_CHANNEL', 'task.events'),
236236
],
237-
238-
'log_folder' => env('TOTEM_LOG_FOLDER', 'totem'),
239237
];

src/Events/Executed.php

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

33
namespace Studio\Totem\Events;
44

5-
use Illuminate\Support\Facades\Storage;
65
use Studio\Totem\Notifications\TaskCompleted;
76
use Studio\Totem\Task;
87

@@ -14,24 +13,18 @@ class Executed extends BroadcastingEvent
1413
* @param Task $task
1514
* @param string $started
1615
*/
17-
public function __construct(Task $task, $started)
16+
public function __construct(Task $task, $started, $output)
1817
{
1918
parent::__construct($task);
2019

2120
$time_elapsed_secs = microtime(true) - $started;
2221

23-
if (Storage::exists($task->getMutexName())) {
24-
$output = Storage::get($task->getMutexName());
22+
$task->results()->create([
23+
'duration' => $time_elapsed_secs * 1000,
24+
'result' => $output,
25+
]);
2526

26-
$task->results()->create([
27-
'duration' => $time_elapsed_secs * 1000,
28-
'result' => $output,
29-
]);
30-
31-
Storage::delete($task->getMutexName());
32-
33-
$task->notify(new TaskCompleted($output));
34-
$task->autoCleanup();
35-
}
27+
$task->notify(new TaskCompleted($output));
28+
$task->autoCleanup();
3629
}
3730
}

src/Providers/ConsoleServiceProvider.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Studio\Totem\Providers;
44

55
use Illuminate\Console\Scheduling\Schedule;
6-
use Illuminate\Support\Facades\Storage;
76
use Illuminate\Support\ServiceProvider;
87
use Studio\Totem\Events\Executed;
98
use Studio\Totem\Events\Executing;
@@ -34,10 +33,6 @@ public function schedule(Schedule $schedule)
3433
{
3534
$tasks = app('totem.tasks')->findAllActive();
3635

37-
Storage::makeDirectory(config('totem.log_folder'));
38-
39-
Storage::put(config('totem.log_folder').'/test.txt', 'abcdegf');
40-
4136
$tasks->each(function ($task) use ($schedule) {
4237
$event = $schedule->command($task->command, $task->compileParameters(true));
4338

@@ -48,10 +43,9 @@ public function schedule(Schedule $schedule)
4843
$event->start = microtime(true);
4944
Executing::dispatch($task);
5045
})
51-
->after(function () use ($event, $task) {
52-
Executed::dispatch($task, $event->start ?? microtime(true));
53-
})
54-
->sendOutputTo(Storage::path($task->getMutexName()));
46+
->thenWithOutput(function ($output) use ($event, $task) {
47+
Executed::dispatch($task, $event->start ?? microtime(true), $output);
48+
});
5549
if ($task->dont_overlap) {
5650
$event->withoutOverlapping();
5751
}

src/Repositories/EloquentTaskRepository.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Support\Arr;
77
use Illuminate\Support\Facades\Artisan;
88
use Illuminate\Support\Facades\Cache;
9-
use Illuminate\Support\Facades\Storage;
109
use Studio\Totem\Contracts\TaskInterface;
1110
use Studio\Totem\Events\Activated;
1211
use Studio\Totem\Events\Created;
@@ -195,13 +194,12 @@ public function execute($id)
195194
$start = microtime(true);
196195
try {
197196
Artisan::call($task->command, $task->compileParameters());
198-
199-
Storage::put($task->getMutexName(), Artisan::output());
197+
$output = Artisan::output();
200198
} catch (\Exception $e) {
201-
Storage::put($task->getMutexName(), $e->getMessage());
199+
$output = $e->getMessage();
202200
}
203201

204-
Executed::dispatch($task, $start);
202+
Executed::dispatch($task, $start, $output);
205203

206204
return $task;
207205
}

src/Traits/HasFrequencies.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,6 @@ public function getCronExpression()
116116
return $this->expression;
117117
}
118118

119-
/**
120-
* Get the mutex name for the scheduled task.
121-
*
122-
* @return string
123-
*/
124-
public function getMutexName()
125-
{
126-
return config('totem.log_folder').DIRECTORY_SEPARATOR.'schedule-'.sha1($this->expression.$this->command.$this->parameters);
127-
}
128-
129119
/**
130120
* Determine if the filters pass for the event.
131121
*

0 commit comments

Comments
 (0)