Custom clockwork on geroku

I just inherited the Rails project before it was on a typical "nix server". It was decided to transfer it to the hero for the client, and it depends on me to make the background process work. Currently, it uses every time to schedule daily events (email, etc.) and run a delayed job queue at startup.

Heroku provides an example documentation for a user-generated synchronization process using a clock mechanism, can I use it anytime in this example? Any pitfalls I could meet? Do I need to create a separate working speaker?

Scheduled Tasks and Custom Clock Processes in Ruby with Clockwork

+6
source share
2 answers

Yes - the Heroku cedar stack allows you to run everything you want.

The main building block of the cedar stack is dyno. Each dino receives an ephemeral copy of your application, 512 MB of RAM and a bunch of total processor time. Web speakers are expected to connect the HTTP server to the port specified in the $PORT environment variable, since where Heroku will send HTTP requests, but other than that, the web dyno is identical to other types of speakers.

Your application tells Heroku how to run its various components by defining them in Procfile . (See Declaring and scaling process types using Procfile .) The article “Clock Processes” demonstrates a template in which you use a dynamic worker (that is, non-web) to work in a queue depending on an arbitrary criterion. Again, you can do whatever you want here - just define it in Procfile and Heroku will be happy to launch it. If you go with the clock process (for example, 24x7 whenever ), you will use the whole dyno ($ 0.05 / hour) to do nothing but the work schedule.

In your case, I would rather switch from Everywhere to Heroku Scheduler . The scheduler is basically a cron running in Heroku where the crontab entries are "expand the dyno and run this command." You will still pay $ 0.05 per hour for additional dinosaurs, but unlike setting the clock + worker, you will only pay for the time they actually spend. It purely separates periodic tasks from stationary web traffic + work traffic, and it is usually much cheaper.

The only other warning is that periodic tasks in distributed systems are complex and have complex failure modes. Some platform incidents (corresponding to major EC2 interruptions) led to such things as 2 simultaneous clock processes and duplication of scheduler work. If you are doing something that needs to be run in series (for example, by email once a day), think about protecting it when locking RDBMS and double-checking that it actually was ~ 23 hours from the moment of your daily work.

+9
source

Heroku Scheduler is often a bad option for use in production, as it is unreliable and sometimes misses its task.

The good news is that if you start a job queue queue with Sidekiq , there are scheduling plugins for it, for example. sidekiq-cron . With this, you can use the same speaker for planning. And if you do not already have a workplace, you need to set it up only for planning, if you need to run it reliably.

PS if you are fortunate enough to run Delayed :: Job for a queing job, there are also planning plugins for it. this one .

0
source

Source: https://habr.com/ru/post/924884/


All Articles