Skip to content

Repository files navigation

Go Report Repository Top Language GitHub go.mod Go version GitHub last commit

I/O-Bound Task Manager HTTP API

A simple, extensible Go service that lets you enqueue and track long-running I/O-bound jobs (3–5 minutes) entirely in memory, without any external databases or message brokers.

Features

🥂 Clean architecture

🍓 Standard Go-project layout

🌸 Easy to use commands

🐳 Docker, Docker-compose

💥 Easy to expand

🤡 Stub server simulates I/O bound tasks

Table of Contents

HOWTO

Clone the project

git clone https://github.com/shishmarevv/http_io_bound
cd http_io_bound

DOCKER

Build images

make build

Run

make up

Logs

make logs

Exit

make down

Run locally

Install dependence

go mod download

Run API

make run-api

Run Stub-server

make run-stub

Use commands (CLI)

Open shell

make CLI

Use taskcli [command]

taskcli help

Run tests

To run tests, write following

go test -v ./...

Add new Task type

Edit handler

internal/web/handlers.go

func (handler *Handler) CreateTask(writer http.ResponseWriter, request *http.Request) {
	errlog.Post("Got JSON, Decoding...")
	var taskrequest TaskRequest
	if err := json.NewDecoder(request.Body).Decode(&taskrequest); err != nil {
		errlog.HTTPCheck(writer, "invalid JSON payload", http.StatusBadRequest)
		return
	}

	errlog.Post("Creating Task...")
	var fn func(context.Context) (string, error)
	switch taskrequest.Type {
	case "stub":
		fn = task.IoTask
		
	//INSERT NEW TYPE AND ITS LOGIC HERE
		
	default:
		errlog.HTTPCheck(writer, "unknown task type", http.StatusBadRequest)
		return
	}

	id := handler.Manager.CreateTask(fn)
	errlog.Post(fmt.Sprintf("Created Task ID: %s", id))

	writer.Header().Set("Location", "/tasks/"+id)
	writer.WriteHeader(http.StatusAccepted)
}

CLI

  • Add new .go file to cmd/taskcli/create
  • cmd/taskcli/create/create.go
func init() {
	Cmd.AddCommand(
		stub, //INSERT NEW TYPE
	)
}

Usage

CLI

Logs

LICENSE

MIT

Contact

Author: Viktor Shishmarev

Github: @shishmarevv

LinkedIn: shishmarevv

About

HTTP API to manage I/O bound tasks

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages