newbie: Can I have fly running only when needed or just two hours a day?

hi

I have a working solution in node.js. Web scrapping using headless Chrome. It is a service that is called and returns what I need. But I need that service only now and then.

I used to use fly when there was a free Hobby plan that is not available any more. I would like you to help me find out if I am able to use fly either

  1. just for an hour in the morning and an hour in the evening or
  2. the machine would start only when needed

When reading about Fly.io Resource Pricing · Fly Docs I understood that I have to pay for 1GB of rootfs for a Machine stopped.

So I have questions

  • how many GB are needed for node.js machine? The script is just few lines of code
  • is there a way to attach temporarily volume to a machine? Or how does it work if the machine needs to download 10GB file then upload it somewhere and delete locally?
  • can I start machine just twice a day for one hour? Or have it started only on demand?

If I need help to set up such solution is someone willing to help me?

Thank you
Radek

1 Like

Fly has “scale to 0” when dealing with requests. But for specific cron-like activities, supercronic still the best for it.

The storage you pay is for the machine usage, if you don’t store data in the machine volume, should be fine for small amounts. As a reminder, you can increase the volume but can’t downscale it, so just increment as it needs.

One idea of setup is:

  1. Private app (doesn’t handle external requests) via flycast so you can scale easily
  2. Cron job via supercronic that calls (via curl or similar) said app and that’s it, should be well within the “free allowance”, if you need to call more times, or allow external calls, should be easy to modify as needed.
2 Likes

so in your setup I would need two machines?

Can I use Autostop/autostart Machines · Fly Docs to start machine based on demand?

Yes, one super small machine to handle the cron calls, and one “bigger” machine to handle the scraping and whatever you want to do.

Big not as a full spec’d machine, but one that is able to handle chromium and whatever you need, is only “up” when you curl it, so 99% of the is “sleeping”.

so the small machine would be up all the time? I want to avoid any machine to be up all the time.

Something has to be up to execute or coordinate stuff, the difference is that you will manage it or not. I don’t think fly has a “cron manager” directly, so it’s up to you to handle that.

hmm, and am I able to start machine remotelly? Via a call from php?

I am lost with the new pricing… so if I run the minimum machine for supercronic would there be any cost?

Try using their calculator (I’m not sure if it’s 100% accurate, it was buggy in the past)
https://fly.io/calculator?m=0_0_0_0_0&f=c&a=no_none&b=sea.100&r=shared_0_1_sea&t=10_100_5&u=0_1_100&g=1_shared_730_1_256_sea_0_1

You can drop the cron machine and use GitHub or GitLab actions to schedule an HTTP request to wake up your worker machine. That way you only pay for the 2 hours or so of the machine running.

1 Like

great! that is what I wanted to hear.

So the github can wake up that machine. how about dropping? Can the machine itself drop itself?

You can also use Run a new Machine · Fly Docs

You just exit w/ status code 0 to stop the machine. Non zero will restart the machine.

one more question… can node.js machine that run webserver exit with status 0?

Any main process, regardless of w/e language, can exit w/ any code.

hmmm, can’t I use public base URL: https://api.machines.dev to start / stop machine? as needed?

how long does it take to start such machine? Is that in ms?

It depends on how big your machine is, but generally should only take a few ms to start up. You probably have the wrong api key to your machine - impossible to tell w/o any errors.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.