Nakilon's blog

A bit about the "scraper web service" freelance project

In the last post I promised to publish some notes about the freelance project I was working on. So task was to deploy a scraper as a web service with REST interface and in the end there were 5 docker containers:

... -> nginx -> webrick -> sidekiq -> scraper
                v     v    v     v
                v  invoker.rb   redis
                v    v
               sqlite.db

At first I wanted to use Yandex Cloud Message Queue but the API consumer wants to have a view on queued tasks that is impossible (by design?) in case of YMQ. The sad part of the story is that the "sidekiq queue" is a thing scattered on several lists of different kinds and one can't just "check the queue" -- it's kind of undocumented and seems to lead to race conditions.
The invoker.rb is a source file that is required by both sidekiq and the webrick server that is creating jobs -- personally I don't like it but it's by Sidekiq design. Or am I missing something?
The sqlite.rb is required by both services because the job stores (writes) results obtained from the "scraper" container and then Webrick reads them.
The docker images used are 2x"ruby:2.7-alpine", 2x"redis:alpine" and one "nginx:stable-alpine".

Now the random notes:

require "webrick"
WEBrick::HTTPResponse.class_eval do
  def create_error_page
    @body = "#{self.status} #{@reason_phrase}"
  end
end
SERVER = WEBrick::HTTPServer.new Port: ENV.fetch("PORT")
END{ SERVER.start }

You include it and then define the routes.

And now the tool compose-launcher. What is it for? I made it when I had a server that was several years old and that hosted multiple applications each with it's own docker-compose config. The compose-launcher is a tool for such cases to [re]deploy multiple non-related applications.

---
- :dir: scraper
  :repo: nakilon/my-repo
  :branch: dev
  :cd: dir-with-compose-config
  :compose: special
  :pre: touch consumer/sqlite.db
- :dir: another_project
  ...

When you run the tool with the above example config, it:

What else? Oh yeah, I've added RSS and email subscription options to this blog ..) they are available at the Home page.

#blog #chromium #docker-compose #gem ferrum #ruby #sidekiq #vk api #webrick