Posts

Showing posts with the label coding

Redis smooth throttling

Image
This might be an edge case and not even complicated, but I thought I'd share it. So, I had this use case recently where I needed to throttle email send out speed, while allowing to control it on admin panel. However, the difference from the usual case was that you don't enter for example how many emails to allow per minute or second, but you enter over how long the hole process should be done. So, for example, send all ~1k emails over 1 hour. Luckily, laravel has redis throttling built in. We can utilize it like so: <?php Redis :: throttle ( 'key' ) -> allow ( 1000 ) -> every ( 3600 ) // 1 hour -> then ( function () { /* send */ }, function () { /* release */ }); But, here lies the problem. In this case it will send all that 1000 emails as fast as possible. It might take only a couple of minutes. If you have more than 1k emails, the queue will wait for the remaining time, do nothing, and then after 1 hour will send a bunch of ...

Hello world!

At least that's what we programmers make our computers to say, when we learn a new programming language. Welcome to my new blog! I am Ernestas from Lithuania, however I have recently moved to the Netherlands. I enjoy coding since childhood and have been more and more interested in self growth, healthy mind and body. Therefore, I hope to combine those two things end not only to grow as a person, but grow the code I write also. This is what this blog will mostly be about. I had a blog before. Frankly, it's still up and running. You can read it here  https://forex-blog.pro/ . However, the hosting I use had upgraded PHP version, which caused some issues and I was forced to reinstall the CMS, therefore loosing all the changes and fixes I have made. Moreover, it was focused mainly on forex. However, my plans have changed a little bit and many times I wanted to share something related to coding, but not necessarily to forex. That's why I decided to create a new blog. I will no...