This is a Go service that implements both synchronous (single-threaded) and asynchronous (multi-threaded) task execution. Tasks are submitted via HTTP POST requests and can be processed in either mode.
- Async mode: Uses goroutines for concurrent task processing
- Sync mode: Processes tasks sequentially in a single thread
- SQLite database for persisting completed tasks, index on task_id for faster lookup
- Configurable failure threshold and retry mechanism at most 3 times
- HTTP API endpoint for task submission, immediate log indicating task completed / failed / duplicated.
brew install sqlite
-
Build the Program
Open a terminal in the project directory and run:
go build
This command compiles the Go service and generates the executable
goTaskExecutor
. -
Run the Task Executor
In the same terminal, start the Task Executor with the desired mode and failure percentage:
./goTaskExecutor <async/sync> <failurePercentage>
<async/sync>
: Choose between asynchronous (async
) or synchronous (sync
) task processing.<failurePercentage>
: An integer between 0 and 100 representing the percentage chance of task failure to simulate unreliable environments.
Example:
./goTaskExecutor async 20
This command runs the Task Executor in asynchronous mode with a 20% failure rate.
-
Generate Task Requests
Open another terminal in the project directory and execute the task request generator script:
./taskReqGenerator.sh
This script sends HTTP POST requests to the Task Executor to submit tasks for processing.
-
Monitoring and Logs
The Task Executor logs task processing details to the console. Monitor these logs to observe task execution, retries, and failures. The Task Request Generator logs the results of each request to
responses_<timestamp>.txt
. -
Database Access
Completed tasks are persisted in the SQLite database located at
./completedTasks.db
. You can inspect the database using any SQLite client:sqlite3 completedTasks.db
Example Query:
SELECT * FROM completedTasks;
./clearDb.sh
go test -v