Skip to main content

Assignment

Design a system with producer and a consumer.
Producer produces some entities independent of consumer
Consumer consumes the entities, producing new entities.
Click here for usage/commands.

Solution

Here, let the job be a string of length 10.

Using async and await, functions can be turned into coroutines to be passed to a execute_function command.

graph TD;
    A["PersistentQInterface"]-- child class ---B["Producer(s)"];
    A-- child class ---C["Consumer(s)"]
    B-- submit jobs -->D["PersistentQSQlite"]
    D-- process jobs -->C

System

Consists of abstract class (ABC) PersistentQInterface, children Producer, Consumer and Cleaner.
Also consists of class PersistentQSQLite that performs SQL queries on a database from Python.

On being called, Producer generates a file name (and file), and submits this file name as a job. PersistentQSQLite adds this name to a queue/SQL database. Occurs every 5 seconds
Consumer reads this queue and processes them, generating a new file with the processed content. Occurs every 7-15 seconds.
If after n tries a file is not able to be processed by Consumer, it gets renamed with a .failed extension. Cleaner checks for .failed files every 30 seconds and deletes them.
Wait times for Producers, Consumers and Cleaners are independent amongst themselves and each other.


Usage

atk-training-rin-q-basic --help

To run the web app, try

atk-training-rin-q-basic web-app

The program will open in localhost:8000. producer and consumer will be running in the background -- any logs/output produced (primarily by consumer) will be visible in the terminal.
NOTE: All files produced will be in the CURRENT DIRECTORY BY DEFAULT. To set your custom path, modify the path in config.yaml.

Setting up your own config

Parameters can be customised by giving the command path to a config.yaml file.
The parameters along with their default values are as follows. If any parameter is missing from the file, the default value will be used.
consumer:
    n_time: 3600
    n_tries: 3
general:
    primary_path: current/directory
    n_prod: 1
    n_cons: 1

n_time : Seconds a consumer is allowed to spend on one job before skipping n_tries : Number of time a consumer is allowed to try a job (in case of errors) before skipping primary_path: Path where files are created n_prod : Number of producers n_cons : Number of consumers

Release files for atk-training-rin-q-basic 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for atk-training-rin-q-basic 0.1.0
File Size Uploaded
atk_training_rin_q_basic-0.1.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for atk-training-rin-q-basic 0.1.0
File Interpreter ABI Platform
atk_training_rin_q_basic-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size:12.9 kB

Release files / atk_training_rin_q_basic-0.1.0.tar.gz

Download URL atk_training_rin_q_basic-0.1.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
956d0b12a37ce0686de00234ff5599d29b6781bb815c85925f715b71b64bbb65
BLAKE2b-256 checksum
How to use checksums
9600f7cb0dbbe3c7bccdf8d3ce9861501f34fb30ebd8cc5130cd690f5831b948
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-46-generic

Release files / atk_training_rin_q_basic-0.1.0-py3-none-any.whl

Download URL atk_training_rin_q_basic-0.1.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fadd24a1de23e5c6ccc68e5f79112851c90f12cae571bf7c99cbc63caf90a902
BLAKE2b-256 checksum
How to use checksums
cd0cd2faf3bda892171ae60ae523d837415fd36aa418a1685dbf4c356c5e36fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-46-generic

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page