How to write a robust system level service - some key learning - 如何写好一个健壮的系统级服务

Scenario: Rewriting a quartz job service.

Background: The existing service logic was hardcoding every job‘s cron expression into xml file. This makes the debugging/tuning of each single jobs very difficult. For example. if a job runs once everyday during midnight, and you want to trigger the job manually during daylight time, or you want to stop that job because it has a bug, you have to shutdown the web site, change the xml file and restart. But it‘s not possible to stop a running web site whenever you want. Hence we have the requirement to re-write this basic service.

Key features:

1. The detailed configration of each single quartz jobs should be stored in DB, rather than xml file (including Java bean name, target method, cron expression etc.)

2. There should be a centralized job factory service, which can read job configurations from database.

3. Each job can be enabled or disabled, and the cron expression can be changed without altering the state of the running web site.

4. Each job can be manually triggered without altering the cron expression. (By changing the cron expression itself, this function can be done, by you have to restore the orginal cron expression, in some cases this is not very convenient)

Some key learnings and critical modifications during the stabilization of the service:

1. (Not related to this topic): Several different ways to implement the quartz job factory, one is to use the reflection mechanism to use class name to init a new object and call thet target method to run, another is to get the java bean from the spring context. However, the first one cannot be used because some referred objects are initialized by spring framework, you cannot simply get it done by a "new".

2. Think carefully, double check each code branch, not to run into dead ends, endless loops.

3. There is a flag for each job in db, indicating enabled or disabled state. The job factory should load all the jobs from DB, including disabled ones. If you only load enabled jobs, the job will never be disabled. (For those disabled jobs, you need to check whether they are still running. if yes, shut it down.)

4. There is a flag to set "manual trigger". If set to 1, the job will be triggered immediately. You should disable the manual trigger back to 0 immediately when you read the job, not to wait till the task ends because the task might take long time.

5. Add a local config file in each environment to switch the job factory on or off. By default off. The job factory should read from this local file to get the switch. This happens when several different developers are connecting to 1 DB. You will find you can hardly trigger your job because other computers are competing with you.

时间: 2024-10-25 01:37:32

How to write a robust system level service - some key learning - 如何写好一个健壮的系统级服务的相关文章

如何在Service中将捕获的错误写到一个文件中

1 private void LogError(Exception ex) 2 { 3 string Path = AppDomain.CurrentDomain.BaseDirectory + @"\ErrorLog.txt"; 4 FileStream file = new FileStream(Path, FileMode.OpenOrCreate); 5 StreamWriter Write = new StreamWriter(file); 6 Write.WriteLine

android 系统级 service详解

一.android 系统级 service简要说明 android系统级的服务包含了Android Service 和Native Service . Android Service 也称作 Java Service ,是用JAVA语言编写的,实现在框架层. Native Service 也称作 System Service ,是用C++语言编写的,实现在Runtime层. 对于这两种service来说,两个对等service通讯都是利用binder,只不过一种利用*.aidl,一种利用IInt

Loaded:loaded(/usr/lib/systemd/system/iptables.service;enabled)Active: inactive

[[email protected] ~]# service iptables start Redirecting to /bin/systemctl start  iptables.service [[email protected] ~]# /bin/systemctl start  iptables.service [[email protected] ~]# service iptables status Redirecting to /bin/systemctl status  ipt

System Center Service Manager 2012 R2 删除项目和重置

用过System Center Service Manager的人应该知道,SCSM中有大量的Workitem,默认情况下是无法删除的,并且每个项目的ID编号会越来越大,但是作为ID人员,我们很多的Service Request等需要多次的测试和调试,在测试中生成的很多项目都是无效的或者无用的,下面就讲一下怎么删除这些无效的项目. 首先需要在SCSM服务器上安装SMLets库,这个库提供了更多的SCSM的Powershell语句和功能. 下载链接:http://smlets.codeplex.c

Ubutntu安装docker启动报Removed /etc/systemd/system/docker.service.

Ubutntu安装docker启动报Removed /etc/systemd/system/docker.service.的错误,只需要执行以下三条命令. systemctl unmask docker.service systemctl unmask docker.socket systemctl start docker.service 原文地址:https://www.cnblogs.com/li-bing/p/9245783.html

C#制作Windows service服务系列二:演示一个定期执行的windows服务及调试(windows service)

系列一: 制作一个可安装.可启动.可停止.可卸载的Windows service(downmoon原创) 系列二:演示一个定期执行的windows服务及调试(windows service)(downmoon) 系列三: windows service系列三--制作可控制界面的windows service 一.经常有人问起如何让程序定期自动执行? 除了像系统任务和SQL JOB/DTS等都可以满足不同的用户需求外,这里演示了如何做一个简单的windows serivce的框架.主要的功能是按照

接收对 http://192.168.1.18:8001/ObtainData/Service 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。

[2015/8/5 19:28:49]错误信息:接收对 http://192.168.1.18:8001/ObtainData/Service 的 HTTP 响应时发生错误.这可能是由于服务终结点绑定未使用 HTTP 协议造成的.这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致.有关详细信息,请参见服务器日志.异常类型:System.ServiceModel.CommunicationException程序集:mscorlib方法:Void HandleReturnMes

Deploying OpenFire for IM (instant message) service (TCP/IP service) with database MySQL , client Spark on linux部署OpenFire IM 消息中间件服务

Are you a hacker? How to build another QQ/Wechat/whatsapp/skype/imessage? Let's go through this!!!! Materials: A linux/unix/windows/mac computer/server, and do some basic things! Are you feeling high? Okay, let's ride the rocket! Get materials: 1. A

Stop a hung service 关闭一个无响应的windows 服务

If you ever have trouble with a service being stuck in a 'starting' or 'stopping' state, you can run a couple of simple commands to kill the service. 1. Query the process To kill the service you have to know its PID or Process ID. To find this just t