简体   繁体   中英

How to confirm if the same task is finished on multiple server instances

I have scheduler job which every X minutes checks if there is some file on sftp server, downloads it, parse and upload status file which says that file is downloaded successfully. If file is not downloaded and parsed successfully we don't upload status file.

Status file is used by 3rd party application which based if the status file exists on sftp server, it starts doing some another job. If there is no status file it will not start the job.

Problem starts with multiple server instances which are running the same scheduler job. I can't figure it the best way how to ensure that all servers are successfully downloaded file and tell to 3rd party app with status file that it can start his job?

The only way how I can communicate with this 3rd party app is through status file.

Some solutions:

  1. before we were running a scheduler job only on one server and have shared disk between them to use this files. This not a option anymore

  2. I was thinking to upload a status file in wrong format (so that 3rd party app don't start his job) with some server id and that will be confirmation that this server has downloaded the file. All other servers will also put their id's in the same file. Then, first server which will find out that there are at least 3x times mentioned the same server id's ( 3x server1, 3x server2, 3x server3) it will change status file in correct format and then 3rd party can start his job. In theory problems could happen if in file was mention 3x times server1 and server2, but server3 was not mentioned at all (all servers have same the same cron expression, like every 2 minutes)

  3. Use some configuration where will be defined number of servers which need to download file, and based on that config I could check if all of them has write their id's in fake status file. Problems is if I add new server I need to update config file.

I guess this is common problem and there is some pattern or algorithm?

If I were you, I would try to create an "interface file" between the 3rd party app and the sftp servers. The "interface file" would periodically (every X minutes) be updated. If the status files are ready (all of them), then only the "interface file" will be marked as "ready". Then send this "interface file" to the 3rd party app.

Hope it helps with your problem

EDIT : syntax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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