<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anurag Tiwari on Medium]]></title>
        <description><![CDATA[Stories by Anurag Tiwari on Medium]]></description>
        <link>https://medium.com/@t2013anurag?source=rss-6bba19934b81------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zQIxWN8p9MuU6lSz0HWZgw.png</url>
            <title>Stories by Anurag Tiwari on Medium</title>
            <link>https://medium.com/@t2013anurag?source=rss-6bba19934b81------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 18:52:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@t2013anurag/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why don’t I love the crypto ecosystem anymore?]]></title>
            <link>https://t2013anurag.medium.com/why-i-dont-love-crypto-space-anymore-f632f5088c79?source=rss-6bba19934b81------2</link>
            <guid isPermaLink="false">https://medium.com/p/f632f5088c79</guid>
            <category><![CDATA[love]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[dogecoin]]></category>
            <dc:creator><![CDATA[Anurag Tiwari]]></dc:creator>
            <pubDate>Fri, 14 May 2021 07:27:12 GMT</pubDate>
            <atom:updated>2021-05-16T17:54:27.915Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*MPe3rSJdwmg6BaAb6ElCsg.jpeg" /><figcaption>An investor with a broken heart (Source: Google Images)</figcaption></figure><p>My love for crypto has been there since the very early stages. I remember reading the Bitcoin whitepaper on my bunkbed way back in 2013. I was so fascinated by the idea that I started buying crypto worth Rs 100 ($1.5) out of the Rs. 1500($20) I received per month as pocket money.</p><p>Over a period of 5 years, I ended up accumulating around 3 ETH and 0.4 BTC. I had to sell a fraction of it often to cover my expenses. Everything was good then. I used to save and buy whenever I could.</p><p>Fast forward to the beginning of this year, we have around 5000 cryptocurrencies. To give you all an example, we have around 10k cities on our planet Earth. Hmm, so we have almost 1 cryptocurrency for every 2 cities. We have 164 official currencies circulating on our planet, so for every 1 official currency, we have around 31 cryptocurrencies.</p><p>But, let’s not get distracted by these numbers. It’s ok, we know from history — Survival of the fittest. A lot of these coins are built on a very strong foundation, their intent is super cool but most of these coins are a scam. A lot of new investors get trapped and they end up losing a lot of money.</p><p><strong>What’s happening now?</strong></p><p>Let me tell you a story about this billionaire who I admire. I really appreciate his vision and I was(am 😕) his fan. He talked a lot about how the crypto industry is going to change the world and how crypto would eventually be the end of centralization. This was all good and yeah we were on the same page.</p><p>But, then there was this whisperer (aka Twitter) and our billionaire was overwhelmed by it. It’s like he became the master of the entire space. He would whisper to his disciples(aka followers) and could move mountains.</p><p>One day, he would whisper that he was gonna use Bitcoin for transactions in one of his companies. Everyone became so excited, everyone thought that this is the start of a new world, <strong>a decentralized world.</strong></p><p>The next day, he would whisper a meme (aka Dogecoin), and his followers would go and Yolo their savings into Doge.</p><p>The next day, he would go ahead and host a live show and call this meme coin a <strong>hustle</strong>. Investors would start to freak out and sell their doge.</p><p>The next day, he would whisper that his company won’t accept Bitcoin anymore because of environmental concerns, freaking out followers into selling their Bitcoin.</p><p>The next day, he would whisper that he is really excited about Doge. He would collaborate with Doge developers to make it more stable. The freaked out followers freaked would Yolo their savings again.</p><p>By now, I think you would have a clearer picture of what’s going on. A single whisper can manipulate my beloved crypto space by tons. The very thing which was supposed to be decentralized is now more centralized than ever. The very thing which was supposed not to be manipulated or controlled has become the most controlled space.</p><p>As an investor, my beliefs are shaken. I don’t want the crypto space to become another playground for the market manipulators. I want everyone to go back in time and remember why they started investing in crypto. It was not about just making money, it was more than that, it was a belief that together we can be strong and live in a decentralized world. It was a belief that we would together innovate and build stuff that actually matters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f632f5088c79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enable MySQL bin log in osx (Mac)]]></title>
            <link>https://t2013anurag.medium.com/enable-mysql-bin-log-in-osx-mac-30511ce56ccc?source=rss-6bba19934b81------2</link>
            <guid isPermaLink="false">https://medium.com/p/30511ce56ccc</guid>
            <category><![CDATA[mysql-binlog]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[binlog]]></category>
            <category><![CDATA[mysql-server]]></category>
            <dc:creator><![CDATA[Anurag Tiwari]]></dc:creator>
            <pubDate>Thu, 12 Dec 2019 06:30:38 GMT</pubDate>
            <atom:updated>2019-12-12T06:30:38.323Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TmxEVGcwaGQKkOKT4KhhIw.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81f9b2abff48eb05a786c6643ee43110/href">https://medium.com/media/81f9b2abff48eb05a786c6643ee43110/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30511ce56ccc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails — Adding global hooks for rake tasks]]></title>
            <link>https://t2013anurag.medium.com/rails-adding-global-hooks-for-rake-tasks-7faf0844364?source=rss-6bba19934b81------2</link>
            <guid isPermaLink="false">https://medium.com/p/7faf0844364</guid>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[rake]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Anurag Tiwari]]></dc:creator>
            <pubDate>Sun, 10 Nov 2019 11:19:14 GMT</pubDate>
            <atom:updated>2019-11-10T11:22:56.113Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rails — Adding global hooks for rake tasks</h3><p>Rake is an internal DSL implementation in the Ruby programming language. It allows Ruby code to define tasks that can be run in the command line.</p><p>Let’s take an example of a simple rake task</p><pre># numbers.rake</pre><pre>task :numbers do<br>  (0..10).each {|x| puts x}<br>end</pre><p>To run this rake task simple do — rake numbers</p><p>What if you want to execute some piece of code before and after this rake task? It can be some common code — like calculating the time taken for the task to run. An easy way is to write that logic inside the rake task itself. It would look something like this -</p><pre># numbers.rake</pre><pre>task :numbers do<br>  start_time = Time.current<br>  (0..10).each {|x| puts x}<br>  end_time = Time.current<br>  puts &quot;Duration =&gt; #{end_time - start_time}&quot;<br>end</pre><p>This looks messy and if you want the same logic for another rake task you’ll have to duplicate this or move it out to separate function. There’s a better way. Rake provides a way toenhance a task with prerequisites or actions.</p><p>With enhance you can implement before and after hooks for your rake tasks. The structure becomes like this -</p><pre># numbers.rake</pre><pre>task :before_hook<br>  @start_time = Time.current<br>end</pre><pre>task :after_hook<br>  end_time = Time.current<br>  duration = end_time - @start_time<br>  puts &quot;Duration =&gt; #{duration}&quot;<br>end</pre><pre>task :numbers do<br>  (0..10).each {|x| puts x}<br>end</pre><pre>Rake::Task[&#39;numbers&#39;].enhance [:before_hook, :after_hook]</pre><p>This will enhance the rake task to add before_hook and after_hook tasks as well. There’s a small issue with this. My after_hook was getting invoked before the main task.</p><p>Ideal order of execution is =&gt;</p><p>before_hook | main_task | after_hook</p><p>But in reality, the execution in the order</p><p>before_hook | after_hook | main_task</p><p>To fix this — add an at_exit in the after_hook. This ensures that the after_hook method gets invoked at the exit. The at_exit method takes a block and registers it for execution at the exit of the program. The updated code looks like this -</p><pre># numbers.rake</pre><pre>task :before_hook<br>  @start_time = Time.current<br>end</pre><pre>task :after_hook<br>  at_exit do<br>    end_time = Time.current<br>    duration = end_time - @start_time<br>    puts &quot;Duration =&gt; #{duration}&quot;<br>  end<br>end</pre><pre>task :numbers do<br>  (0..10).each {|x| puts x}<br>end</pre><pre>Rake::Task[&#39;numbers&#39;].enhance [:before_hook, :after_hook]</pre><p>The updated code ensures the correct order of execution.</p><h3><strong>Adding global hooks to the rake task</strong></h3><p>Adding these before and after hooks to all your rake tasks is pretty simple. All you’ve to do is to update the Rakefile in your Rails application.</p><pre>Rakefile</pre><pre>task :before_hook do<br>  @start_time = Time.current<br>end</pre><pre>task :after_hook do<br>  load &#39;lib/hr_logger.rb&#39;<br>  at_exit do<br>    end_time = Time.current<br>    duration = end_time - @start_time<br>    puts &quot;Duration =&gt; #{duration}&quot;<br>  end<br>end</pre><pre>tasks = Rake.application.tasks<br>tasks.each do |task|<br>  next if [Rake::Task[&#39;before_hook&#39;],<br>           Rake::Task[&#39;after_hook&#39;]].include?(task)</pre><pre>  task.enhance([:before_hook, :after_hook])<br>end</pre><p>Notice the exclusion of Rake::Task[&#39;before_hook&#39;] and Rake::Task[&#39;after_hook&#39;] . This is done to avoid the circular dependency error. What is that circular dependency? What is the cause of it? Figure it out and leave the answer in comments.</p><figure><img alt="Circular Dependency" src="https://cdn-images-1.medium.com/max/1024/0*ZmN17jLIFTGdTZ9g" /><figcaption>Photo by <a href="https://unsplash.com/@hautier?utm_source=medium&amp;utm_medium=referral">Christophe Hautier</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Thanks for reading. Happy hooks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7faf0844364" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails — Shared Redis connection pool between Sidekiq and Application]]></title>
            <link>https://t2013anurag.medium.com/rails-shared-redis-connection-pool-between-sidekiq-and-application-a448f78fdb35?source=rss-6bba19934b81------2</link>
            <guid isPermaLink="false">https://medium.com/p/a448f78fdb35</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[connection-pool]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[sidekiq]]></category>
            <dc:creator><![CDATA[Anurag Tiwari]]></dc:creator>
            <pubDate>Thu, 20 Jun 2019 14:58:20 GMT</pubDate>
            <atom:updated>2019-06-20T14:58:20.989Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rails — Shared Redis connection pool between Sidekiq and Application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lU1RT5oQLylNFhbrzK3RXw.png" /></figure><p>Connection Pooling is a cache of database connections that can be reused when future requests to the database are required. So, does that mean you open all the connections on the application boot up? No, you would rather just define the minimum pool of connection required and then lazy load them.</p><p>Just in case you’re not familiar with Sidekiq read <a href="https://medium.com/@t2013anurag/configuring-rails-5-with-sidekiq-adapter-and-redis-queues-e32c7050d204">my previous article.</a></p><p>We will connection pool and use it both for the application requirements and background jobs processors like <strong>Sidekiq, Resque, ActiveJob, etc.</strong></p><p>Install Connection Pool gem (not required if you already have sidekiq installed.)</p><pre>gem install connection_pool</pre><p>Now in your sidekiq initializer define the Redis configuration as:</p><pre># frozen_string_literal: true</pre><pre># using pool to share connection b/w application and sidekiq<br># sidekiq required minimum connection of (2 + concurrency)<br># <a href="https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/redis_connection.rb#L51">https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/redis_connection.rb#L51</a></pre><pre>REDIS_POOL = ConnectionPool.new(size: 10) { Redis.new(url: ENV[&#39;REDIS_URL&#39;]) }</pre><pre>Sidekiq.configure_server do |config|<br>  config.redis = REDIS_POOL<br>end</pre><pre>Sidekiq.configure_client do |config|<br>  config.redis = REDIS_POOL<br>end</pre><p>Note: Sidekiq needs <strong>2 connections</strong> by default for a bunch of stuff like a heartbeat, maintain sentinel, etc. <a href="https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/redis_connection.rb#L51">Read here.</a> That’s why if you have max threads or concurrency of for ex. 5 then you need to have at least 7 connections in your pool.</p><p>The sidekiq workers will utilize the Redis pool for processing background jobs. To use the pool in the application —</p><pre># store `foo` with value `bar` in redis<br>REDIS_POOL.with do |client|<br>  client.set(&#39;foo&#39;, &#39;bar&#39;)<br>end</pre><pre># retrieve value of key `foo`<br>REDIS_POOL.with do |client|<br>  client.get(&#39;foo&#39;)<br>end</pre><p>All Redis operations can be performed inside the block. Brush up on Redis <a href="https://redis.io/commands">here</a>.</p><h4>Benefits of using Connection Pool:</h4><ol><li>Connections are lazily created. No unnecessary connections created until required.</li><li>Ruby Garbage Collection takes care of orphaned connections and cleans them.</li></ol><p>Though as per the documentation of connection pool your connections should be self-repairing as there is no provision for <a href="https://github.com/mperham/connection_pool#notes">health checking.</a></p><p>More on Sidekiq and Rails:</p><ol><li><a href="https://medium.com/@t2013anurag/configuring-rails-5-with-sidekiq-adapter-and-redis-queues-e32c7050d204">Configuring Rails 5 with Sidekiq Adapter and Redis Queues.</a></li><li><a href="https://medium.com/@t2013anurag/rails-5-configuring-sidekiq-to-use-cron-scheduler-74ab1d45c187">Configuring Sidekiq to use Cron Scheduler.</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a448f78fdb35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails 5 — Configuring Sidekiq to use cron scheduler]]></title>
            <link>https://t2013anurag.medium.com/rails-5-configuring-sidekiq-to-use-cron-scheduler-74ab1d45c187?source=rss-6bba19934b81------2</link>
            <guid isPermaLink="false">https://medium.com/p/74ab1d45c187</guid>
            <category><![CDATA[background-jobs]]></category>
            <category><![CDATA[sidekiq]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[cron]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Anurag Tiwari]]></dc:creator>
            <pubDate>Fri, 12 Apr 2019 05:27:04 GMT</pubDate>
            <atom:updated>2019-04-12T05:27:04.819Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Rails 5 — Configuring Sidekiq to use cron scheduler</strong></h3><p>If you are not familiar with sidekiq usage go through <a href="https://medium.com/@t2013anurag/configuring-rails-5-with-sidekiq-adapter-and-redis-queues-e32c7050d204">this blog post</a> first.</p><p>A cron job is time-based <a href="https://en.wikipedia.org/wiki/Job_scheduler">job scheduler</a> in <a href="https://en.wikipedia.org/wiki/Unix-like">Unix-like</a> computer <a href="https://en.wikipedia.org/wiki/Operating_system">operating systems</a> (src: Wikipedia). Setting up a cron tab is pretty easy but you can take advantage of your running rails application for doing so.</p><p>Sidekiq can also be used to run cron jobs. This can be done with<a href="https://github.com/moove-it/sidekiq-scheduler"> sidekiq-scheduler</a> gem.</p><pre>gem install sidekiq-scheduler</pre><p>Let’s start with creating a job which would run as a scheduled cron job</p><pre># app/jobs/demo_job.rb</pre><pre># frozen_string_literal: true</pre><pre>class DemoJob &lt; ApplicationJob<br>  def perform<br>    puts &#39;I run at 8 everyday&#39;<br>  end<br>end</pre><p>Add the following to configuration file from <a href="https://medium.com/@t2013anurag/configuring-rails-5-with-sidekiq-adapter-and-redis-queues-e32c7050d204">previous blog</a></p><pre># config/sidekiq.yml</pre><pre>---<br>:verbose: false<br>:concurrency: &lt;%= ENV.fetch(&quot;RAILS_MAX_THREADS&quot;) { 5 } %&gt;<br>:timeout: 30</pre><pre>:queues:<br>  - [low_priority, 1]<br>  - [high_priority, 2] # high priority</pre><pre>:schedule:<br>  DemoJob:<br>    cron: &#39;0 8 * * *&#39;<br>    queue: scheduler<br>    enabled: true</pre><p>This tell sidekiq handlers to create a cron schedule running at 8 everyday. The job will be queued to scheduler queue.</p><p>That’s it, now you can forget about setting up a cron tab.</p><p><strong>Useful commands</strong></p><ol><li>Get all schedules</li></ol><pre>Sidekiq.get_schedule</pre><pre># this returns =&gt;<br>{&quot;DemoJob&quot;=&gt;{&quot;cron&quot;=&gt;&quot;0 8 * * *&quot;, &quot;queue&quot;=&gt;&quot;scheduler&quot;, &quot;enabled&quot;=&gt;true, &quot;class&quot;=&gt;&quot;DemoJob&quot;}}</pre><p>2. Set dynamic schedule</p><p>Schedule changes are loaded every 5 seconds. To allow dynamic schedule add dynamic: true in the sidekiq configuration file.</p><pre># This will run demo job every min</pre><pre>Sidekiq.set_schedule(&#39;DemoJob&#39;, { &#39;every&#39; =&gt; [&#39;1m&#39;], &#39;class&#39; =&gt; &#39;DemoJob&#39; })</pre><p>3. To see the scheduler jobs in the sidekiq dashboard. Add this to your routes.rb</p><pre>require &#39;sidekiq/web&#39;<br>require &#39;sidekiq-scheduler/web&#39;</pre><pre>mount Sidekiq::Web =&gt; &#39;/sidekiq&#39;</pre><p>Go to /sidekiq</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P86HxAsTV1EJ42Dv9L5HAw.png" /><figcaption>Sidekiq web dashboard for recurrent jobs.</figcaption></figure><p>4. You can use <a href="https://crontab.guru/#">cron tab guru</a> to verify cron schedule.</p><p>That’s all you need to know to set up a cron scheduler. To know more about the options available you can check the<a href="https://github.com/moove-it/sidekiq-scheduler"> official git repo</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74ab1d45c187" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring Rails 5 with sidekiq adapter and redis queues]]></title>
            <link>https://t2013anurag.medium.com/configuring-rails-5-with-sidekiq-adapter-and-redis-queues-e32c7050d204?source=rss-6bba19934b81------2</link>
            <guid isPermaLink="false">https://medium.com/p/e32c7050d204</guid>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[sidekiq]]></category>
            <category><![CDATA[background-jobs]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Anurag Tiwari]]></dc:creator>
            <pubDate>Tue, 09 Apr 2019 05:03:08 GMT</pubDate>
            <atom:updated>2019-04-12T05:31:08.248Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rails 5 with sidekiq adapter and redis queues</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pyt9sP_NlCQ-XtO0nbslUg.png" /><figcaption>Sidekiq</figcaption></figure><p>Sidekiq is a thread based efficient background processing solution for ruby. Read more about it <a href="https://github.com/mperham/sidekiq/">here</a>.</p><p>Let’s start configuring sidekiq for our application. First thing we need is to sidekiq as a gem. Sidekiq installs redis as a dependency.</p><pre># in your Gemfile<br>gem install sidekiq</pre><p>By default sidekiq tries to connect to Redis at localhost:6379 . You can define your redis configuration via initializer.</p><pre># config/initializers/sidekiq.rb<br>Sidekiq.configure_server do |config|<br>  config.redis = { url: &#39;redis://redis.example.com:7372/0&#39; }<br>end<br><br>Sidekiq.configure_client do |config|<br>  config.redis = { url: &#39;redis://redis.example.com:7372/0&#39; }<br>end</pre><p>More options to play around are <a href="https://github.com/mperham/sidekiq/wiki/Using-Redis">available here.</a></p><p>After your sidekiq and redis is in place, now it’s time to define sidekiq configuration. First we define the queue adapter as sidekiq in the application.</p><pre># config/application.rb<br>config.active_job.queue_adapter = :sidekiq</pre><p>Now let’s create one worker job</p><pre># app/jobs/hello_world_job.rb</pre><pre># frozen_string_literal: true</pre><pre>class HelloWorldJob &lt; ApplicationJob<br>  queue_as :low_priority</pre><pre>def perform<br>    puts &#39;Hello World!&#39;<br>  end<br>end</pre><p>This is a simple hello world job which queues the job to low_priority queue. To run this job just start the sidekiq handler with this queue.</p><pre>bundle exec sidekiq -q low_priority</pre><p>This will run jobs enqueued to low_priority queue. This is also an example of <strong>reserved</strong> <strong>queues </strong>— meaning this queue will handle only low_priority jobs.</p><p>But what if you want to run multiple queues? Passing them as arguments is allowed but can be a headache. This is where sidekiq configuration comes into place. In this configuration, you can define multiple queues, their priorities, timeout, concurrency, etc.</p><p>By default sidekiq looks for the configuration file in config/sidekiq.yml and if the file is present the workers start with defined configuration. You can also define the custom path to your configuration and run it with bundle exec sidekiq -c config/your_sidekiq_config_path/config_name.yml</p><pre># config/sidekiq.yml</pre><pre>---<br>:verbose: false<br>:concurrency: &lt;%= ENV.fetch(&quot;RAILS_MAX_THREADS&quot;) { 5 } %&gt;<br>:timeout: 30</pre><pre>:queues:<br>  - [low_priority, 1]<br>  - [high_priority, 2] # high priority</pre><p>There are 2 queues defined with different priorities in the above configuration. The high_priority queue lookup is twice the lookup of low_priority queue. So processing of jobs is like 22122122… (where 2 priority jobs are executed and then one low priority.)</p><p>You can define concurrency based on the machine configuration you are running your workers on. By default one sidekiq process starts 10 threads. Read more about <a href="https://github.com/mperham/sidekiq/wiki/Advanced-Options#concurrency">concurrency here.</a></p><p><strong>Configuring Sidekiq Dashboard</strong></p><p>Sidekiq provides a dashboard to manage jobs. You can enable it by defining a route in your routes.rb .</p><pre>require &#39;sidekiq/web&#39;<br>mount Sidekiq::Web =&gt; &#39;/sidekiq&#39;</pre><p>Let’s say your application is running on localhost:3000, you can access the dashboard on localhost:3000/sidekiq . Setting up authentication around the dashboard can be found <a href="https://github.com/mperham/sidekiq/wiki/Monitoring#authentication">here</a>.</p><p>The dashboard will look something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4oarFJXN7Z-AWE6PmEGcg.png" /><figcaption>Sidekiq Dashboard (Source <a href="https://github.com/mperham/sidekiq">https://github.com/mperham/sidekiq</a>)</figcaption></figure><p>That’s all. It’s easy to configure sidekiq. The performance of sidekiq vs Resque can be seen <a href="https://medium.com/@t2013anurag/rails-5-configuring-sidekiq-to-use-cron-scheduler-74ab1d45c187">here</a>. The official sidekiq wiki is available <a href="https://github.com/mperham/sidekiq/wiki">here</a>.</p><p>Learn how to use cron schedulers with sidekiq in <a href="https://medium.com/@t2013anurag/rails-5-configuring-sidekiq-to-use-cron-scheduler-74ab1d45c187">another blog post.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e32c7050d204" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails timestamped seed files]]></title>
            <link>https://t2013anurag.medium.com/rails-timestamped-seed-files-a091b24a82ca?source=rss-6bba19934b81------2</link>
            <guid isPermaLink="false">https://medium.com/p/a091b24a82ca</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[seeds]]></category>
            <category><![CDATA[ruby-on-rails-development]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[activerecord]]></category>
            <dc:creator><![CDATA[Anurag Tiwari]]></dc:creator>
            <pubDate>Mon, 08 Apr 2019 08:39:40 GMT</pubDate>
            <atom:updated>2019-04-08T18:22:25.217Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rails run seeds in specific order (timestamp your seed files)</h3><p>Many a times when you generate a model and create a seed file for it, you do so by initializing an empty seed file where name is like model_name_seed.rb (At least that’s how I do it!!)</p><p>But what if you want to generate seeds that you want to run in a specific order? Then it becomes a bit tricky. While there are multiple ways to achieve it, the easiest approach I feel is to create timestamped seed files.</p><p>The biggest advantage of this is that they always run in the order of creation and that’s how rails read them while running.</p><p>rails db:seed</p><p>Also, another advantage is timestamp prefixed seed files are always ordered in any development IDE or tools.</p><p>It’s quite simple and easy to implement =&gt;</p><pre># frozen_string_literal: true</pre><pre>namespace :seed do<br>  desc &#39;Generate an empty seed file, Usage =&gt; rake seed:create&#39;<br>  task create: :environment do<br>    seed_path = &quot;db/seeds/#{Time.now.to_i}_seed.rb&quot;<br>    FileUtils.touch(seed_path)<br>    exit<br>  end<br>end</pre><p>Let this rake task reside inside `/lib/tasks/seed.rake`</p><p>Now every time you generate a model just run</p><pre>rake seed:create</pre><pre># This would create seed like =&gt; db/seeds/1554711746_seed.rb</pre><p>If you want to generate seed with a specific name, update your rake task to accept arguments from console</p><pre>namespace :seed do<br>  desc &#39;Generate an empty seed file, Usage =&gt; rake seed:create seed_name&#39;<br>  task create: :environment do<br>    argument = ARGV[1]<br>    argument = &quot;_#{ARGV[1]}&quot; if argument.present?<br>    seed_path = &quot;db/seeds/#{Time.now.to_i}#{argument}_seed.rb&quot;<br>    FileUtils.touch(seed_path)<br>    exit<br>  end<br>end</pre><p>Now to create a seed run the command</p><pre>rake seed:create my_model</pre><pre># This would create seed like =&gt; db/seeds/1554711746_my_model_seed.rb</pre><p>The rake task can further be improved to write default logic to the created seed file as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a091b24a82ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>