Ask HN: What is the cheapest, easiest way to host a cronjob in 2022?
I thought this could start a good debate on the subject. Myself I have had to make a short running web-scraping job that, given a change in the site, sends a notifying email. This running once an hour.
It is 2022, so I had thought it would be tremendously easy and cheap, but it seems no solution is easily implemented.
335 comments
[ 2.6 ms ] story [ 286 ms ] threadI tried to do Chromium/Puppeteer based scraping this way.
Building a Dockerfile took ages due to the low compute. (Rust was a non-starter).
I also had (foolishly) only bought the Pi with 2GB instead of 8GB so RAM was an issue.
Disk was super slow.
I'm not sure how viable this is, especially with how hard it is currently to source a Pi, let alone its computation/memory constraints.
I have a Raspberry Pi that is natively running a scraper using headless Chromium and cron. It works great, except....
I ended up needing a virtual framebuffer. I got it working on the Raspberry Pi, but I got a new workstation and wanted to edit my script and test it there. I got cryptic errors that I needed to debug to understand they were framebuffer issues, then attempt to recreate the setup that's running on my Pi, then debug that.....
My first mistake was not writing down what I did in my README, but a Docker image would have saved me a ton of time here.
Isn't proposing Docker as a solution to this going nuclear?
I think there are some many cheaper things you can do to solve this.
For me this is absolutely no justification for Docker use in this scenario.
A lot of websites can detect the IPs from this and block it, basically almostly like a CAPTCHA.
I had other needs like Postgres, etc.
Scraping data is one thing, actually doing anything with it is another. I quickly hit the limits of a $50 RaspberryPi 4 or whatever they're going for on Amazon these days with the gouging, etc.
Why compile anything on the raspberry pi? Cross-compile on a machine with more compute (like your laptop, desktop, phone, or ec2 instance) one time, and then transfer the compiled binaries or built docker image over.
> Pi with 2GB instead of 8GB
For headless chrome, that should be enough unless you're doing other stuff with it. Unless you mean for compiling stuff, which as before can be done elsewhere.
First of all the answer recommends to use either a Pi or a VPS. If a Pi doesn't cut it for you, just switch to a VPS with sufficient specs for your requirement. Problem solved, now it's viable.
Besides, a significant part of the web can be scraped without resorting to a heavyweight browser such as Chromium. It should always be the last resort. Even if you have to evaluate Javascript (in case of SPAs), there are much cheaper solutions than Puppeteer (JSDOM being an example) which can get the job done most of the time.
As to Docker, I fail to see why you would need Docker for this kind of job, unless you don't know how to do it without Docker.
When there is no portability requirement, the costs of Docker easily surpass its benefits.
...
So no, it's not that what's being recommended in the answer is not viable. You're doing it wrong. Either you're using a Pi when you need to use a VPS or you are introducing unnecessary layers.
[1] https://learn.microsoft.com/en-us/azure/azure-functions/func...
Not free but basically you wrap your job in http endpoint and then we take care of the rest.
I remember seeing a couple projects shared before, using this technique to scrape sites with GHA
I use their cronjob functionality to ensure my docker images are built daily and therefore in theory secure.
This works perfectly for my case (content syndication for https://potato.horse), and I’m pretty happy with GH actions for this kind of stuff, but if you need something more precise, you might want to look somewhere else.
Is the spread really that egregious? That's essentially a 50% failure to trigger at all, like I don't think you can call that 15 minutes so much as 15±10 minutes lmfao
IIRC AWS EventBridge is also not guaranteed to execute on the exact minute, but in my experience running a small job every 5 minutes only had about a 30-40 second delay at worst.
Can't you configure a GHA which commits nonsense every month?
This seems to meet OP’s use case as they have to commit state anyway.
[0] https://docs.github.com/en/actions/managing-workflow-runs/di...
Simon Willison has a bunch of examples of scraping sites with GHA and storing the results in a repo. But you can use the same technique without the storing part if need be.
https://github.com/patrickgalbraith/rageagain/blob/master/.g...
You won't spend much at all, it's fractions of a penny per call and I think there's a free tier.
It's cheap as in free, thanks to the generous free tier.
there it is an apt-get away
Thanks!
* free-tier vps on GCP or Oracle Cloud
* lambda job on AWS
I have a cheap VPS I use for other things and just run my cron jobs there.
The UI is excellent for this. You can probably find cheaper on Fly but probably not easier.
Even easier, maybe more expensive than Render:
https://www.zeplo.io/docs/schedule
You just hit a URL like so and it's done. zeplo.to/your_url.com?_cron=5|14|||*
From their pricing example:
> You schedule a job to run once an hour for 15 seconds. This job uses 50% of one CPU core and 256 MiB of memory. This job will cost $0.016/day for the CPU, and $0.001/day for the memory, adding up to $0.017/day, or $0.51/month.
Easiest way I found to do that was Azure Functions. Costs me about 35p per month. Mostly for storage for logs as far as I can tell. I'd sort that, but it's literally not worth the time it would take
Send an email (for free): https://blog.cloudflare.com/sending-email-from-workers-with-...
That said, there are probably different forces at play if this is a personal infrastructure question: while cheap is good, if you aren't fluent in AWS it may be a slog to set up. If you're not, easiest thing is probably a real cron job run on a cheap VPS.
https://chrome.google.com/webstore/detail/distill-web-monito...
https://developers.google.com/apps-script
It's free, so pretty cheap.
You can set up a schedule to run the scripts. Has easy access to Google APIs (Gmail).
Very powerful and simple solution I've used for years.
There's a hosted solution, or you can self-host it
Does exactly what it says and gets bonus points due to self-hosted or as-a-service.
https://fly.io/docs/machines/working-with-machines/#create-a...
See the `schedule` parameter.