Skip to content

Perthys/stylua-public-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stylua public service

side project, trying to get unrust at rust (pun intended). basically a public stylua service for luau, web based, publicly accessible, with a studio plugin on top

since most plugins either compile rust --> wasm --> lua through wasynth and pack each plugin distribution with stylua (super slow), or they require an external/local web server making them super annoying to setup. if i just host one plugin-facing public api the whole community can use it, and bonus points i get to unrust

how it works

three crates:

  • crates/api - axum server, formats inline when theres capacity, otherwise queues the job and hands you a session id
  • crates/worker - drains the queue, visibility timeout + reaper so dead workers dont eat jobs
  • crates/shared - types, redis store, config parsing

config is just stylua config as json. unknown keys get ignored, actually invalid values (like a garbage enum variant) get you a 400 instead of silently formatting with defaults

endpoints

  • GET /health
  • POST /v1/format - { "code": "...", "config": { ... } }, 256kb max. formats inline when it can, 202 + session id when it cant
  • POST /v1/sessions - same body, always queues
  • GET /v1/sessions/{id} - session status
  • GET /v1/sessions/{id}/result - formatted code, 409 if not ready yet, 422 if formatting failed
  • DELETE /v1/sessions/{id}

running it

needs redis, then:

REDIS_URL=redis://localhost:6379 cargo run -p api
REDIS_URL=redis://localhost:6379 cargo run -p worker

env vars, everything except REDIS_URL is optional:

  • PORT - api port, default 3000
  • MAX_QUEUE - queue cap before the api starts returning 503, default 1000
  • VISIBILITY_TIMEOUT_SECS - how long a worker can hold a job before the reaper requeues it, default 30
  • POLL_INTERVAL_MS - worker poll rate, default 200
  • FORMAT_TIMEOUT_SECS - per job format timeout, default 5
  • REAP_INTERVAL_SECS - default 10

Dockerfile builds the api, Dockerfile.worker builds the worker

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors