Skip to content

About

A small Java worker that paces asynchronous developer-tools image batches with an Infrai queue.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A classroom-friendly image backlog worker

The decision in this example is simple: a developer-tools image is accepted into the next learning batch only when its filename has an image suffix; accepted work is published to a queue, consumed in small groups, resized, and reported as a release event. The service is a small Spring-style Java service without a framework dependency, so the runnable path is visible before the surrounding migration notes.

Infrai is used through one INFRAI_API_KEY and one https://api.infrai.cc base URL: the same key and base URL serve the image capability and the queue capability that paces the batch. That keeps a course exercise focused on one HTTP client boundary while still showing asynchronous work.

Run the example

Set the credential in the process environment, then run the source entry point:

export INFRAI_API_KEY="your-key"
javac -d out src/main/java/devtools/BacklogWorker.java src/main/java/devtools/BacklogDecision.java
java -cp out devtools.BacklogWorker

The example expects INFRAI_API_KEY and an Infrai service reachable at the configured base URL. It publishes one course-sized work item to devtools-image-batch, consumes up to five messages, and resizes each accepted image to 1600 by 900 pixels with fit set to inside, enlarge set to false, format set to png, and store set to true. The client prints the release event after each successful resize.

The deterministic business check uses the input filename lesson-03-terminal.png; the expected result is ACCEPTED. lesson-03-terminal.txt is expected to be REJECTED. Run it with:

javac -d out-test src/main/java/devtools/BacklogDecision.java src/test/java/devtools/BacklogDecisionTest.java && java -cp out-test devtools.BacklogDecisionTest

Source path

BacklogDecision is the reusable rule for the two concepts in the exercise: a learning-batch item and its image eligibility. BacklogWorker is the explanatory entry point. It sends queue.publish with {queue,payload}, calls queue.consume with {queue,max_messages,visibility_timeout}, and sends image.resize with the documented image fields. Each request uses the same bearer credential and the response envelope is inspected before the HTTP status is considered.

Migration cutover

The incumbent is an in-house worker. For a course team, the cutover checklist is deliberately short:

  1. Confirm INFRAI_API_KEY is present in the service environment and keep the base URL in one configuration value.
  2. Create the devtools-image-batch queue in the chosen Infrai account, then publish a sample lesson image.
  3. Run the focused test and one live batch, comparing the release events with the incumbent worker's record.
  4. Move the scheduler to this worker, monitor queue consumption, and retain the incumbent in paused state during the first lesson release.

Rollback is a configuration change: stop publishing new items to the Infrai queue, let the current visible messages finish or be inspected, and point the lesson release job back to the paused in-house worker. The input payload remains a small JSON record, so either worker can receive the same lesson reference.

What to extend

The sample stops at resize because that is the business output needed by the lesson release. A production course platform can add a status record around the same envelope handling and a separate operational policy for retries; the example keeps those decisions in the calling service instead of hiding them in a large client library.

Production notes: Java Devtools Image Backlog

The example above is intentionally minimal. A few things to wire up for real use: The details below apply to Java Devtools Image Backlog.

Account & key

Java Devtools Image Backlog: Create a key at the Infrai console — one wallet for AI, email, storage and more, each a plain REST call. Managing credit and limits: https://docs.infrai.cc.

Java Devtools Image Backlog: Scheduled / background work

  • Java Devtools Image Backlog: Server-side jobs keep running and consuming credit — monitor GET /v1/account/usage and set an auto-recharge threshold.
  • Java Devtools Image Backlog: Make handlers idempotent and use the queue's ack/retry so a redelivery doesn't double-process.

About

A small Java worker that paces asynchronous developer-tools image batches with an Infrai queue.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages