I am running automatic tests and after each test, all the sessions of these tests are automatically inserted into a temporary table.
My tool (in JAR), checks this temporary table and when it finds a new session inserted, my tool scans it and then delete this entry from the temporary table.
Actually I can do that manually without any problem (telling my tool to check the temporary table, if there is something new, scan it…), but I want to do that automatically, I mean my tool always running, and checks automatically (for example every hour) if there is something new in the temporary table.
Could you help me how I can do that ? I guess I need a server where I execute my tool 24/24, which type of server? Thank you very much
If you are on a unix based system, you could run the jar as a cronjob. The following would run a jar every 30 seconds.
*/30 * * * * java -jar /path/to/jar/myjar.jar
Read the following to learn how to setup a cronjob correctly https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job
For windows, use task scheduler. https://stackoverflow.com/a/26932169/802061 as suggested by #kevin-esche in the comments
Which database you are using.
If SQL, you can create the jobs in the database server itself.
Related
I have recently moved from an old database migration provider to flyway (4.1.2). In our setup we have - as usual - some incremental scripts and scripts that are repeatable. So far things have worked well and I was able to recreate most of the behavior we had before with some improvements thanks to flyway. However I am experiencing weird behavior with repeatable scripts.
Lets imagine the following scripts:
DELETE FROM CONFIGURATION;
INSERT INTO CONFIGURATION (KEY, VALUE) VALUES ('SAF_DELAY', '22');
it gets executed when created and does what it is supposed to. Also an entry in schema_version is created with the checksum. Now I change the 22to 23and run flyway:migrate again, the script is executed and creates a second entry in schema_version with the new checksum. A while later I realize that the 23 is actually bad and 22 was right from the beginning so I change it back.
Now flyway refuses to execute the script again telling me that everything is up to date even though the script has changed from its previous state. I am assuming it does so because it can still find the old entry in the schema_version.
Obviously that is undesired behavior for a repeatable script, the decision point should only be the last executed checksum and not any checksum that ever executed of the script. This is also what I assume the documentation means by "Instead they are (re-)applied every time their checksum changes." I was looking through the configuration section of the maven plugin but could not find anything that seemed like a solution.
Since this is kind of a deal breaker for me I would be happy if you could hint me to the right direction.
I am writing a sample application in which I wrote all sql in files.
Whenever I added new functionality I am creating new sql script.
What technology should I use when my application run first check all the script if not exist create or if any new script added create that one only. I gave files name like script1.sql,script2.sql and so on.
You are using a set of sql scripts to set up your DB. Every time you have a modification you add another script - incremental script.
You can use DB maintain for managing them. It will hold information about which scripts were executed and it will know to just execute the last patch. It seems to be exactly what you are looking for:
Keeps track of what scripts were executed ( DB version )
Can ease deployment to another environment ( with a lower DB version )
Can do much more than that , but it seems this is what you need.
PS Not sure if there are other frameworks which can do the same.
I am developing a web application to migrate images from CVS to Adobe CQ. There is a requirement to maintain versioning for the images in a database table. The flow is as follows:
Check Out files from CVS -- returns a list of all files checked out, but does not tell whether a file was updated or newly added to CVS! (Due to the files being binary file, it seems it is not able to detect updates and all files are treated as additions)
Check if this is application's first run, if yes, then treat all files as additions. If not, for every file, check database for presence of record corresponding to this file. If record present, treat as update, else insert
... Carry on with other operations
For every insert, add an entry in the database
I have to detect if the application is running for the first time, or has been run previously. This also needs to support future tasks such as resetting everything and starting the application from scratch.
What would be a good way to do this? The application is hosted in WebSphere in Linux. I have thought of two ways:
a. creating an entry in a file with a flag set to true, which I will have to reset to false after the first run - difficult for a user to reset later
b. creating a .firstrun or similar file in the app folder somewhere and check presence of this file to determine first run, easier to reset for any user
Which of this is a better way? Or is there any other way to do it better?
You mentioned database. Why not to store in db, in even more extended way: when what version, # of runs, etc.
I have a Java - Spring application. I want to set up a feature to listen a file location(Folder) and has to process a file as a file get created in this folder.
My plan is to set up a spring quartz cron job which will run in every five minutes and process the files available.
Please suggest me a better approach.
A choice of solution depends on how quickly an appearance of a waited file must be detected.
If it is not urgently and at least 1 minutes would be OK, then your solution using any kind of cron job would be OK too.
If a file should be detected asap, then you must provide a permanent running program, that detects a file in very short intervals. This can be reached by for this task dedicated daemon. If your program has nothing to do during wait time, then it can contain part for the file detection.
If you have moved on to/are on java8, it provides Watch Service API that allows us to monitor file and folder locations.
Have a look at Watch Service API
I want to run my java program in regular interval , lets say, in every 3 hours. I am thinking to write a .bat file and put command to call java class. But what is the best way to run .bat regularly in windows xp. Thanks in advance. I dont want to use third party tool.
Windows scheduled tasks are built for exactly that purpose.
You can run things on multiple schedules (so you can get your every-three-hour behaviour) and you can get your code to run whether or not logged in.
The multiple scheduling is a bit tricky. You basically set it up as a daily task to start with but, near the end, it will ask you if you want to do advanced features.
Select yes then you can set up multiple schedules at that point.
If you want a pure Java Based solution you can try QUARTZ SCHEDULER. But as paxdiablo already mentioned, Windows Task Scheduler will do that as well.