Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Cron Jobs with Remix
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
MIZOGUCHI Coji
June 02, 2023
Technology
1.7k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Cron Jobs with Remix
Remix でも Cron Job 的なのやりたいですよね!
MIZOGUCHI Coji
June 02, 2023
Other Decks in Technology
See All in Technology
CTO Night|NotionのAIエージェントとFDE
kzkhykw1991
0
100
JAWS-UGグッズ職人仕事の流儀
kentapapa
0
100
Code for Security プロジェクト紹介 2026年10月
yu23ki14
0
110
エンタメ企業のM&Aを支えるデータ基盤 ― 統合から店舗のリアルタイム分析まで / Data Engineering Summit 2026
genda
0
170
「Docker Desktop不要の時代」は 来たのか?
ueponx
0
770
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
170
触りたくないデータに、どう触るか AI時代のRBACアクセスガバナンス
ivry_presentationmaterials
0
260
"優秀な誰か"の下位互換にならないために
yut0naga1_fa
1
1.8k
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
340
Refining Active Record
shugo
0
150
AI時代のPRレビューにどう向き合うか?
kairim0
1
240
サブエージェントと Claude Mods で作る独自 Advisor ツールの話
kenichiodo
2
160
Featured
See All Featured
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
550
Six Lessons from altMBA
skipperchong
29
4.5k
Optimizing for Happiness
mojombo
378
71k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Odyssey Design
rkendrick25
PRO
2
870
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
How STYLIGHT went responsive
nonsquared
100
6.3k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Transcript
Cron Jobs with Remix COJI Remix Casual Meetup Jun. 1th
2023
Coji Mizoguchi coji techtalkjp coji プログラマー
Remix のアプリで Cron Job したい。 メール送信とかの非同期ジョブ ランキングとか集計とかのバッチジョブ crawler などなど Remix
でも Cron Job 的なのやりたいですよね!
Remix のアプリで Cron Job: どうやって? OS の cron を使う remix
上の一部のコードを共有した別アプリを cron から nodejs で起動? remix 上で api 作って、そこに HTTP で呼ぶ処理を別プロセスで cron から nodejs で起動? これでやるにしても、サーバレスだと OS の cron 使えないの多いし。 微妙! クラウドプラットフォームのジョブスケジューラを使ってAPI をコールさせる サーバレスだと実行時間制限が厳しいですね。 OpenAI とかの処理に時間がかかるようなのをジョブで動かそうとすると厳しい 微妙! remix はモノリシックにできるのが良いのに。 Rails と同じつらみ? なるべく最初は構成もシンプルにしたいですよね
Remix が動いてるのは Nodejs 同一プロセス内で非同期ジョブスケジューラを動かせばいいのでは? サーバ環境は fly.io ( 推し) Remix はカスタムサーバで
シンプルな node-schedule を利用 それぞれ続きのスライドで説明します。 Nodejs は非同期処理が得意。
Remix をカスタムサーバで server.ts express に createRequestHandler でマウントしつつ、同じプロセス内でジョブスケジューラを動かしておく。 import path from
'path' import express from 'express' import { createRequestHandler } from '@remix-run/express' import { createJobSchedular } from 'batch/job-schedular' // ジョブスケジューラ const BUILD_DIR = path.join(process.cwd(), 'build') const port = process.env.PORT || 3000 // express サーバに remix をマウントして起動 const app = express() app.all('*', createRequestHandler({ build: require(BUILD_DIR) })) app.listen(port, () => { require(BUILD_DIR) console.log(`Express server listening on port ${port}`) }) // ジョブスケジューラ。ずっと動かしておく const { start } = createJobSchedular() start()
シンプルな node-schedule を利用 めちゃくちゃシンプルに cron と同じ書き方ができるジョブスケジューラです。 import schedule from 'node-schedule'
import { runTask } from './task' export const createJobSchedular = () => { const start = () => schedule.scheduleJob('10 * * * *', async () => runTask()) // 10 分ごとに起動 return { start } }
その結果 ずっとサーバ代無料で安定してうごいてます!メンテも簡単!
結論 fly.io は良い!( 推し)