English 中文(简体)
工作日程安排: 框架
原标题:Job-Scheduling in Play! Framework

I am currently into the development of a play-powered (v. 1.2.4) application where users can perform certain tasks and gain rewards for doing so. These tasks require some energy, which will be refilled over time. The basic setting is as follows:

public class User extends Model {
    public Long energy;
    public Long maxenergy;
    public Long cooldown = Long.valueOf(300);
}

public class Task extends Controller {
    public static void perform(Long id) {
        User user = User.findById(id).first();

        // do some complex task here...

        user.energy--;
        user.save();
        Task.list();
    }
}

现在我想在冷却(5分钟)之后再填充用户的能源。 假设用户有10/10个能源点,我想在使用点5分钟后再填满,我可以很容易地为此利用一个工作:

public class EnergyHealer extends Job {
    public Long id;

    public EnergyHealer(Long id) {
        this.id = id;
    }

    public void doJob() throws Exception {
        User user = User.findById(id);
        user.energy++;
        if (user.energy > user.maxenergy) {
            user.energy = user.maxenergy;
        }
        user.save()
    }
}

... and call it in my controller right after the task has been competed:

new EnergyHealer(user.id).in(user.cooldown);

我这里的问题是,在这种情况下,同时安排工作,因此,如果使用者在完成以前的任务后履行任务2秒,则第一个能源点在5分钟后重新填满,而后两个能源点则重新填满。

因此,我需要一系列的工作,例如,假定我拥有10个能源点中的8个,它应当用exactly 10分钟,直到所有能源点重新填满为止。

在相关说明中:一旦达到一定门槛值,用户在完成任务方面拥有不同水平和经验。 它们的水平有所提高,并重新填满了all<>/strong>的能量点,无论它们中有多少是在以前的水平上使用的,因此有些工作在完成时可能会过时。

考虑到约1 000名用户,工作可能根本不是完美的选择,因此,如果有人想如何实现所述的设想,我会乐于提供帮助!

最佳回答

我认为,你的工作时间安排是错误的。 如果用户已经不存在,那么你就不应每当其采取行动时就放弃工作,而是应该有一间cade子或一片 something子。

  1. 如果工作已经不存在,则创造就业机会,否则就没有任何东西。

  2. 然后,增加1个能源。

  3. 核实能源是否完整,如果是,

  4. 如果不是,暂停5分钟

  5. 页: 1

问题回答

暂无回答




相关问题
JobDefinitions for Timer Jobs in SharePoint

I ve hit an issue with creating a timer job on demand from within an event handler. It works fine on my dev machine where the user is also the farm administrator. On the staging server (and production ...

What account to use for SharePoint 2010 Timer Job

what account do you run the SharePoint 2010 Timer Job service under? Do you use the farm account or a separate one or just local service? Currently I use the farm account but the health analyzer ...

SharePoint 2007 - Audience

We have scheduled to execute the Audience (all) compilation job and found that it is failed to complete with the below error: The audience cannot be compiled while another job in progress if we ...

scheduling runnable tasks in java

I am following up an interesting question on so, on usage of ScheduledThreadPoolExecutor for some repeating task. Scheduling this object returns a ScheduledFuture object which one can use to cancel ...

Sharepoint Timer Job - Which server does the job execute on?

If I install a (timer job) feature to a Sharepoint front end server within a farm, which server executes the job? All of them? The job is locked at the job level, and the Execute method calls a web ...