0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Cloud Run JobsにLaravelのBatchをデプロイした

Last updated at Posted at 2023-11-23
1 / 9

Cloud Run Jobsとはなにか?そして何がいいのか?

詳しくはこちら

ただ、実際に見てみないことにはわからない。

やってみる。


デプロイするまで

作ったコマンド

public function handle()
    {
        try {
            $this->output->info('Start run command ...');
            DB::beginTransaction();
            User::factory()->createOne();
            DB::commit();
            $this->output->success('Command complete');
        } catch (\Throwable $t) {
            DB::rollback();
            Log::error($t->getMessage() . 'in' . $t->getFile() . ':' . $t->getLine());
            return 1;
        }
        return 0;
    }

ビルド

$ docker buildx build --platform linux/amd64 -t us-central1-docker.pkg.dev/obi-dev-405503/test-batch-repo/batch:latest -f docker/batch/Dockerfile .

コンテナをPush

$ docker push us-central1-docker.pkg.dev/obi-dev-405503/test-batch-repo/batch:latest

今回はコンソールからJobを作る

image.png

さっきPushしたイメージからを指定して、

image.png

コマンドや、メモリやCPUなどの設定をして完了


定期実行させる

定期実行のジョブを作成

image.png

これで定期実行はOK

image.png


実行ログ

image.png


失敗した場合のログ

image.png

成功した場合のログ

image.png


まとめ

めっちゃ簡単にバッチ実行ができるし、安い。

image.png

10分以内のジョブを1日1回毎日実行するくらいなら無料らしいから、個人開発においてはこれを使いたいな。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?