简体   繁体   English

如何通过Web应用程序控制Linux Java Cron作业?

[英]How to control Linux java cron jobs from web appication?

Right now we are running java cron jobs on Linux environment. 现在,我们正在Linux环境上运行Java cron作业。 and start/stop of job is doing by Linux commands on putty. Linux上的腻子命令可以开始或停止工作。 which will daily schedule automatically.but my requirement is i want to control those cron jobs from UI(like spring web application). 这将每天自动调度。但是我的要求是我想从UI(例如spring web应用程序)控制那些cron作业。 like starting a job, stopping a job, current running status of job. 例如开始工作,停止工作,工作的当前运行状态。 is there any libraries are available? 有没有可用的图书馆? Please suggest. 请提出建议。 thank you. 谢谢。

Yes, there is check out: http://www.quartz-scheduler.org/ 是的,可以签出: http : //www.quartz-scheduler.org/

It has 3 or 4 SQL tables that you configure and then you can list all jobs, their state, when they'll run next time, etc. 它可以配置3或4个SQL表,然后您可以列出所有作业,其状态,下次运行的时间等。

Just as quick look example: 就像快速浏览示例:

 List<HashMap<String,Object>> jobs = new ArrayList<>();
 Scheduler sch = MyScheduler.getScheduler();
       for (String groupName : sch.getJobGroupNames()) {
        for (JobKey jobKey : sch.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
             String jobName = jobKey.getName();
             String jobGroup = jobKey.getGroup();
             List<Trigger> triggers = (List<Trigger>) sch.getTriggersOfJob(jobKey);
             Trigger tg = triggers.get(0);
             Date nextFireTime = tg.getNextFireTime();

             System.out.println("[jobName] : " + jobName + " [groupName] : " + jobGroup + " - " + nextFireTime);

            HashMap<String,Object> jb = new HashMap<>();
             jb.put("triggerKey", tg.getKey());
             jb.put("triggerGroup", tg.getKey().getGroup());
             jb.put("triggerName", tg.getKey().getName());
             jb.put("nextFireTime", nextFireTime);
             jb.put("trigger_state", sch.getTriggerState(triggers.get(0).getKey()));
             jobs.add(jb);
        }
     }

You may want to check our QuartzDesk Executor (QE) free and open-source app on GitHub. 您可能想在GitHub上查看我们的QuartzDesk Executor (QE)免费和开源应用程序。 QE is a spring-based Java webapp built on top of the popular Quartz scheduler API and out-of-the-box it allows you to schedule execution of the following types of tasks/jobs: QE是基于Spring的Java Web应用程序,基于流行的Quartz Scheduler API构建,并且开箱即用,它允许您调度以下类型的任务/作业的执行:

  • Local executable applications and scripts (eg *.sh, *.exe, *.cmd, *bat). 本地可执行应用程序和脚本(例如* .sh,*。exe,*。cmd,* bat)。
  • Remote executable applications and scripts (through SSH). 远程可执行应用程序和脚本(通过SSH)。
  • Externalized Java Quartz jobs. 外部化的Java Quartz作业。
  • JDBC queries. JDBC查询。
  • HTTP(S) POST requests. HTTP(S)POST请求。

Since the QE is open-source you can extend it and add your own custom types of jobs. 由于QE是开源的,因此您可以扩展它并添加您自己的自定义类型的作业。

QE is mean to be used with our QuartzDesk job management and monitoring platform that provides additional features and a decent GUI. QE旨在与我们的QuartzDesk作业管理和监视平台一起使用,该平台提供附加功能和良好的GUI。 If you decide to give the QuartzDesk platform a try, you will get persistent execution history, visual job execution statistics, job execution notifications (email, instant messages, SNMP Trap, web-service invocation), job chaining etc. 如果您决定尝试QuartzDesk平台,则将获得持久的执行历史记录,可视的作业执行统计信息,作业执行通知(电子邮件,即时消息,SNMP陷阱,Web服务调用),作业链接等。

QuartzDesk can intercept log messages produced by executed jobs. QuartzDesk可以拦截已执行作业产生的日志消息。 These log messages are visible for all currently executing jobs so that you can see what your jobs are currently doing at runtime (!). 这些日志消息对于所有当前正在执行的作业都是可见的,因此您可以在运行时查看作业当前正在执行的操作(!)。 In the execution history view you can see log messages of all finished jobs executions. 在执行历史记录视图中,您可以查看所有完成的作业执行的日志消息。 For OS-native jobs (shell scripts, executable commands etc.), QuartzDesk can intercept messages produced by these jobs on their standard and error output. 对于OS本地作业(shell脚本,可执行命令等),QuartzDesk可以在其标准输出和错误输出上拦截这些作业产生的消息。

This is what the QuartzDesk GUI, that is connected to a QE instance, looks like: 这就是连接到QE实例的QuartzDesk GUI的样子:

QuartzDesk GUI中的QE实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM