同步优化

This commit is contained in:
邓皓元 2019-01-16 11:40:42 +08:00
parent 0929d5a8d0
commit f4ea4fd472
6 changed files with 13 additions and 18 deletions

View File

@ -52,6 +52,8 @@ class MongoSync extends Command
app(ConfigService::class)->set(self::CURSOR_KEY, intval($nextMicrotime)); app(ConfigService::class)->set(self::CURSOR_KEY, intval($nextMicrotime));
MongoSyncJob::onQueue('sync')->withChain($jobs->toArray())->dispatch(1, $this->limit, $utcDateTime); if ($total) {
MongoSyncJob::onQueue('sync')->withChain($jobs->toArray())->dispatch(1, $this->limit, $utcDateTime);
}
} }
} }

View File

@ -93,13 +93,7 @@ class MongoSyncJob implements ShouldQueue
virtual_activated_at=COALESCE(cards.virtual_activated_at, excluded.activated_at), virtual_activated_at=COALESCE(cards.virtual_activated_at, excluded.activated_at),
order_status=excluded.order_status'; order_status=excluded.order_status';
try { $builder->connection->insert($sql, Arr::flatten($values, 1));
$builder->connection->insert($sql, Arr::flatten($values, 1));
} catch (\Exception $e) {
$nextMicrotime = intval($res->first()->oRDate->toDateTime()->format('U.u') * 1000) - 1;
app(ConfigService::class)->set(MongoSync::CURSOR_KEY, intval($nextMicrotime));
}
app(CardRepository::class)->forgetCached(); app(CardRepository::class)->forgetCached();
} }

View File

@ -55,6 +55,9 @@ class CardSync extends Command
app(ConfigService::class)->set(self::CURSOR_KEY, $nextId); app(ConfigService::class)->set(self::CURSOR_KEY, $nextId);
CardSyncJob::onQueue('sync')->withChain($jobs->toArray())->dispatch(1, $this->limit, $maxId);
if ($total) {
CardSyncJob::onQueue('sync')->withChain($jobs->toArray())->dispatch(1, $this->limit, $maxId);
}
} }
} }

View File

@ -5,6 +5,7 @@ namespace App\Domains\Virtual\Commands\Sync;
use Carbon\Carbon; use Carbon\Carbon;
use App\Models\Card\Card; use App\Models\Card\Card;
use App\Models\Virtual\Order; use App\Models\Virtual\Order;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use App\Domains\Virtual\Jobs\LogSyncJob; use App\Domains\Virtual\Jobs\LogSyncJob;
@ -60,6 +61,8 @@ class LogSync extends Command
app(ConfigService::class)->set(self::CURSOR_KEY, $nextId); app(ConfigService::class)->set(self::CURSOR_KEY, $nextId);
LogSyncJob::onQueue('sync')->withChain($jobs->toArray())->dispatch(1, $this->limit, $maxId); if ($total) {
LogSyncJob::onQueue('sync')->withChain($jobs->toArray())->dispatch(1, $this->limit, $maxId);
}
} }
} }

View File

@ -96,12 +96,7 @@ class CardSyncJob implements ShouldQueue
virtual_activated_at=excluded.virtual_activated_at, virtual_activated_at=excluded.virtual_activated_at,
cancelled_at=excluded.cancelled_at'; cancelled_at=excluded.cancelled_at';
try { $builder->connection->insert($sql, Arr::flatten($array, 1));
$builder->connection->insert($sql, Arr::flatten($array, 1));
} catch (\Exception $e) {
$nextId = $res->first()->id - 1;
app(ConfigService::class)->set(CardSync::CURSOR_KEY, $nextId);
}
app(CardRepository::class)->forgetCached(); app(CardRepository::class)->forgetCached();
} }

View File

@ -150,8 +150,6 @@ class LogSyncJob implements ShouldQueue
} }
} catch (\Exception $e) { } catch (\Exception $e) {
DB::rollback(); DB::rollback();
$nextId = $res->first()->id - 1;
app(ConfigService::class)->set(LogSync::CURSOR_KEY, $nextId);
throw $e; throw $e;
} }
} }