kc

command module
v0.0.0-...-ff41c22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2025 License: MIT Imports: 7 Imported by: 0

README

KC

Overview

This is a job-processing system designed to handle multiple store visits within a single job. Each store visit contains multiple images, and the job is considered completed only when all images are processed successfully. If any image processing fails, the job is marked as failed. The system uses Golang for backend development and SQLite database.

Features

  • Submit a job containing multiple store visits and images.
  • Track the status of a job.
  • Concurrent image processing with a success/failure mechanism.
  • Uses SQLite for easy database management.

Project Structure

/kc
│── /dbs                # Database initialization and models
│── /helper             # Utility functions
│── /service            # Business logic for job processing
│── main.go             # Entry point of the application
│── go.mod              # Go module dependencies
│── go.sum              # Dependency checksums
│── README.md           # Project documentation

Technologies Used

  • Golang (Backend)
  • SQLite (Database)
  • net/http (API development)
  • sync (Concurrency handling)
  • GORM and GIN can be used further to optimize SQL queries.

Setup Instructions

Prerequisites

Make sure you have Go installed. If not, download it from here.

Clone the Repository
git clone https://github.com/gourav-112/kc.git
cd kc
Install Dependencies
go mod tidy
Run the Application
go run main.go

The server will start at http://localhost:8080/


My Work Environment

  • OS -> Windows 11 (Home)
  • IDE used -> Visual Studio Code

Database Schema

The system uses GORM for database interactions. The tables are structured as follows:

Jobs Table
Column Type Description
id INT (PK) Unique Job ID
status STRING Job status (ongoing/completed/failed)
Visits Table
Column Type Description
id INT (PK) Unique Visit ID
job_id INT (FK) Associated Job ID
store_id STRING Store Identifier
Images Table
Column Type Description
id INT (PK) Unique Image ID
visit_id INT (FK) Associated Visit ID
image_url STRING Image URL
status STRING Image status (ongoing/completed/failed)

API Endpoints

1. Submit a Job

Endpoint: POST /api/submit

Request Body:

{
  "count": 2,
  "visits": [
    {
      "store_id": "S00339218",
      "image_url": [
        "https://example.com/image1.jpg",
        "https://example.com/image2.jpg"
      ],
      "visit_time": "2025-03-11T12:00:00Z"
    },
    {
      "store_id": "S01408764",
      "image_url": [
        "https://example.com/image3.jpg"
      ],
      "visit_time": "2025-03-11T12:30:00Z"
    }
  ]
}

Response:

{
  "job_id": 123
}
2. Get Job Status

Endpoint: GET /api/status?jobid=123

Response:

{
  "job_id": 123,
  "status": "completed"
}

How Job Processing Works

  1. The submit job API takes a payload with multiple store visits and images.
  2. The backend creates a job entry and associates visits and images with it.
  3. The system processes images concurrently.
  4. If all images are processed successfully, the job is marked as completed.
  5. If any image fails, the job is marked as failed.
  6. The status API helps in tracking the job status.

Further Scope

  • GORM and GIN can be used for optimized database handling.
  • More APIs can be written for the extension of services.
  • Messaging queues can be used.
  • NewRelic and be used for better execution of transactions.
  • Better error handling can be done.

Contribution Guide

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature-branch
  3. Commit your changes: git commit -m "Added a new feature"
  4. Push to your branch: git push origin feature-branch
  5. Submit a pull request.

License

This project is open-source under the MIT License.

Contact

For any queries or issues, feel free to reach out!

📧 Email: gouravbeniwal1746@gmail.com
📌 GitHub Issues: Report an issue

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL