Search code examples
javaplayframeworkprocessbuilderplayframework-1.x

Retrieving Jobs and/or Process


Is there an easy way to retrieve a job and check e.g. the status with Play? I have a few encoding jobs/downloading jobs which run for a long time. In some cases I want to cancel them.

Is there a way to retrieve a list of Jobs or something?

E.g. one Job calls the FFMPEG encoder using the ProcessBuilder. I would like to be able to get this job and kill the process if it is not required (e.g. wrong file uploaded and don't want to wait for an hour before it is finished). If I can get a handle to that Job then I can get to the process as well.

I am using Play 1.2.4


Solution

  • See JobsPlugin.java to see how to list all the scheduledJobs.

    Getting the task currently executed is more tricky but you can find your jobs in JobsPlugin.scheduledJobs list by checking Job class and call a method in your custom Job to tell him to cancel

    Something like

    for (Job<?> job : JobsPlugin.scheduledJobs) {
        if (job instanceof MyJob) {
          ((MyJob) job).cancelWork();
        }
    }
    

    where cancelWork is your custom method