Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA MyTask

From Leeroopedia
Knowledge Sources
Domains Scheduled_Tasks, Image_Generation, Task_Management
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete tool for scheduled processing of the Stable Diffusion queue and Midjourney task timeout management, provided by the Spring Scheduling framework.

Description

The MyTask class contains two scheduled methods:

  • run() — Runs every 5 seconds (@Scheduled(fixedRate = 5000)). If the SD queue has items, it processes the head: deducts credits, translates prompt to English, calls the SD WebUI /sdapi/v1/txt2img or /sdapi/v1/img2img endpoint, saves base64 images locally, delivers results to the user via SendMessageUtil, and removes the item from the queue.
  • checkTasks() — Runs every 30 seconds (@Scheduled(fixedRate = 30000)). Iterates alive Discord instances, finds running tasks that exceed the instance's timeout threshold, fails them, refunds credits, and calls instance.exitTask().

Usage

Import this component when you need to:

  • Process the SD image generation queue
  • Handle MJ task timeouts and credit refunds
  • Understand the scheduled task lifecycle

Code Reference

Source Location

  • Repository: GPT-WEB-JAVA
  • File: src/main/java/com/intelligent/bot/task/MyTask.java

Signature

@Component
public class MyTask {
    @Scheduled(fixedRate = 5000)
    public void run() throws IOException;

    @Scheduled(fixedRate = 30000L)
    public void checkTasks();
}

Import

import com.intelligent.bot.task.MyTask;

I/O Contract

Inputs

Name Type Required Description
(none) — — Reads from Redis queue and DiscordLoadBalancer

Outputs

Name Type Description
run void SD image generated, saved, delivered to user; queue item removed
checkTasks void Timed-out MJ tasks failed, credits refunded, tasks removed from instance

Usage Examples

SD Queue Processing

// run() executes every 5s:
// 1. Check queueUtil.getCurrentQueueLength() > 0
// 2. Get head item: SdCreateReq req = parse(queue[0])
// 3. Deduct credits via checkService.checkUser()
// 4. Translate prompt: baiDuService.translateToEnglish(req.prompt)
// 5. POST to SD WebUI /sdapi/v1/txt2img or /sdapi/v1/img2img
// 6. Save base64 images via FileUtil.base64ToImage()
// 7. Push result via SendMessageUtil.sendMessage()
// 8. Remove from queue: queueUtil.remove(queue[0])

MJ Task Timeout

// checkTasks() executes every 30s:
// 1. For each alive DiscordInstance:
// 2. Find tasks where (currentTime - startTime) > timeoutMinutes
// 3. If task not already terminal: task.fail("任务超时")
// 4. Refund credits based on task action type
// 5. instance.exitTask(task) — cancel Future, remove from queue

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment