This service demonstrates a micro-batching library, which processes tasks in batches to improve throughput. The library allows for submitting jobs, processing them in batches, and retrieving results. It is configurable for batch size and interval, and provides a shutdown method to ensure all jobs are processed before the service exits.
-
Run Docker Container:
docker run --rm -it -v ./:/app -p 8080:8080 golang:1.18-alpine /bin/sh
-
Navigate to the Application Directory:
cd /app
-
Install GCC and Other Necessary Build Tools:
apk update && apk add --no-cache gcc musl-dev
-
Build the Service:
go build -o microbatch-service main.go
-
Run the Service:
./microbatch-service
-
Send Requests:
-
Submit a job:
curl -X POST -H "Content-Type: application/json" -d '{"data":"sample data","value":123}' http://localhost:8080/submit
-
Shutdown the service:
curl -X POST http://localhost:8080/shutdown
-
Get the result of a job:
curl -X POST http://localhost:8080/result?id=3
-
-
Run Unit Tests:
go test ./microbatch
-
Build the Docker Image:
docker build -t microbatch-service .
-
Run the Docker Container:
docker run -p 8080:8080 -e BATCH_SIZE=5 -e BATCH_INTERVAL=10 microbatch-service
- BATCH_SIZE: The number of jobs to accumulate before processing a batch.
- BATCH_INTERVAL: The maximum time interval (in seconds) to wait before processing a batch.
Submit a job to the service:
curl -X POST -H "Content-Type: application/json" -d '{"data":"example data","value":456}' http://localhost:8080/submit
Shutdown the service:
curl -X POST http://localhost:8080/shutdown
Retrieve the result of a job:
curl -X GET "http://localhost:8080/result?id=1"
Ensure all dependencies are installed and the development environment is set up. Run the unit tests to verify the functionality of the micro-batching library.
go test ./microbatch