Skip to content

An actor model to simulate an automated production chain

License

Notifications You must be signed in to change notification settings

thomasperrot/foobartory

Repository files navigation

Foobartory

Python3.6+ compatible Documentation Status Continuous Integration Status Coverage Status MIT License Code style black

An actor model to simulate an automated production chain using Python asyncio.

Here's an example

The foobartory CLI

Quickstart

$ git clone [email protected]:thomasperrot/foobartory.git
$ cd foobartory
$ pip install .

Once you have installed the package, you can run the Foobartory with the following command:

$ foobartory --speed=10 -v

To have details about the available options:

$ foobartory --help
Usage: foobartory [OPTIONS]

Options:
  -s, --speed FLOAT  Fasten the factory by the given factory (1 by default)
  -v, --verbose      Use multiple times to increase verbosity  [x>=0]
  --help             Show this message and exit.

Improvements

I chose to implement this project using Python asyncio. This is a simple and efficient approach, but it could be improved. In particular, a major improvement would be to use a micro-services architectures, where each robot is an independent process. The project would then follow a master slave achitecture, where the master is the Factory, and the slaves are the robots.

  • Each robot is an independent process, that would run synchronous Python code, packaged in Docker.
  • The factory is also an independent process, running synchronous Python code on the host machine.
  • Each robot sends Foo, Bar, FooBar and cash to RabbitMQ independent exchanges. Those four exchanges each have a unique queue, which is listen by all robots.
  • When a robot wants to buy a new robot, it sends a message in a RabbitMQ exchange to inform the factory. This exchange is common to all robots, and have a single queue, which is listen only by the factory.
  • The Factory is in charge of:
    • starting new robots when receiving a message on the dedicated queue. To do this, the factory can use docker-py package
    • stopping robots once 30 robots have been bought. To do this, the Factory sends a stop message to a dedicated exchange, which has one queue per robot. Every robot must stop when a message is received on that queue.

In a production environment, we could even run the robots in GCP (Cloud Run or Kubernetes). Unfortunately, I did not have enough time to implement it.

Where to go from here

The complete docs is probably the best place to learn about the project.

If you encounter a bug, or want to get in touch, you're always welcome to open a ticket.

About

An actor model to simulate an automated production chain

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published