Add bus
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
2efcca2b6a
commit
3273a49336
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace App\Initialize;
|
||||
|
||||
use App\Actions\InsertCoursesAction;
|
||||
use App\Actions\InsertMemberAction;
|
||||
use App\Actions\PullCoursesAction;
|
||||
use App\Actions\PullMembershipsAction;
|
||||
use App\Actions\InsertMembershipsAction;
|
||||
use App\Nami\Api\CompleteMemberToRedisJob;
|
||||
use App\Setting\NamiSettings;
|
||||
use DB;
|
||||
|
@ -14,7 +14,10 @@ use Illuminate\Support\Facades\Bus;
|
|||
use Illuminate\Support\Facades\Redis;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
use Zoomyboy\LaravelNami\Api;
|
||||
use Zoomyboy\LaravelNami\Data\MemberEntry as NamiMember;
|
||||
use Zoomyboy\LaravelNami\Data\Course as NamiCourse;
|
||||
use Zoomyboy\LaravelNami\Data\Member as NamiMember;
|
||||
use Zoomyboy\LaravelNami\Data\MemberEntry as NamiMemberEntry;
|
||||
use Zoomyboy\LaravelNami\Data\MembershipEntry as NamiMembershipEntry;
|
||||
|
||||
class InitializeMembers
|
||||
{
|
||||
|
@ -27,24 +30,30 @@ class InitializeMembers
|
|||
$allMembers = collect([]);
|
||||
Redis::delete('members');
|
||||
|
||||
$jobs = $api->search([])->map(function (NamiMember $member) use ($api) {
|
||||
$jobs = $api->search([])->map(function (NamiMemberEntry $member) use ($api) {
|
||||
return new CompleteMemberToRedisJob($api, $member->groupId, $member->id);
|
||||
})->toArray();
|
||||
|
||||
$batch = Bus::batch($jobs)
|
||||
->finally(function (Batch $batch) {
|
||||
dd(Redis::get('members'));
|
||||
foreach (Redis::lrange('members', 0, -1) as $data) {
|
||||
try {
|
||||
$data = json_decode($data, true);
|
||||
$localMember = InsertMemberAction::run(NamiMember::from($data['member']));
|
||||
InsertMembershipsAction::run(
|
||||
$localMember,
|
||||
collect($data['memberships'])->map(fn ($membership) => NamiMembershipEntry::from($membership)),
|
||||
);
|
||||
InsertCoursesAction::run(
|
||||
$localMember,
|
||||
collect($data['courses'])->map(fn ($course) => NamiCourse::from($course)),
|
||||
);
|
||||
} catch (Skippable $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
})
|
||||
->dispatch();
|
||||
// $localMember = InsertMemberAction::run();
|
||||
// })->catch(function (Batch $batch, Throwable $e) {
|
||||
// // First batch job failure detected...
|
||||
// })->finally(function (Batch $batch) {
|
||||
// // The batch has finished executing...
|
||||
// })
|
||||
|
||||
// app(PullMembershipsAction::class)->handle($localMember);
|
||||
// app(PullCoursesAction::class)->handle($localMember);
|
||||
}
|
||||
|
||||
public function restore(): void
|
||||
|
|
|
@ -28,6 +28,10 @@ class CompleteMemberToRedisJob implements ShouldQueue
|
|||
|
||||
public function handle(): void
|
||||
{
|
||||
if ($this->batch()->cancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Redis::rpush('members', collect([
|
||||
'member' => MemberAction::run($this->api, $this->groupId, $this->memberId),
|
||||
'memberships' => MembershipsOfAction::run($this->api, $this->memberId),
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 42a303d16cc7aa094968e3c212a755f762ce7b16
|
||||
Subproject commit 927bf7a09ce5d1f3cef14e60060c7f885ef140d6
|
Loading…
Reference in New Issue