How to run program that sends bills to customers once a month? - java

I have a table in database with users and their expenses for traveling. I am using GWT and want to run a code once a month, that would query the database and send bills as PDFs to customers. I know how to create PDFs and send emails from servlet.
How to run a program in java (or some other script if it isn't possible with java) that would run once a month?
Tnx

Unix and derivatives: use cron -> http://en.wikipedia.org/wiki/Cron
Windows: use task scheduler -> http://support.microsoft.com/kb/308569
If you want to get fancy and do it purely in java: -> http://www.quartz-scheduler.org/, but do consider OS scheduler first.

you have many choices.
If you are under Unix, the simpliest solution is a batch scheduled with a crontab.
If you prefer a 100% java solution, the Quartz framework is a robust a easy to setup solution.

To avoid "re-inventing the wheel" I suggest using http://www.freshbooks.com/ and tying your app into their API to send your bills. You can easily set up recurrence as a billing option so that the bills get re-sent (along with reminders) each month. The user can then grab the PDF version of their bill.

Related

Can Symfony run Java jobs over Beanstalk?

I'm working on a Symfony 3 (PHP) project.
I would like to launch a Java executable using parameters I got from Symfony.
Some informations to consider:
The executable generates a file as an output.
Execution can take several minutes depending on the input parameters.
Multiple users can trigger the execution simultaneously.
I'm looking for a long-term sustainable solution. Do you have any advice?
After some research on queues.io, I found out that Beanstalk for PHP seems to be fitting my needs, but I would like to confirm or infirm this position with you.
What would you do in a similar case?

Scripting to access Steam Team Fortress 2 account information

Bit of a random question :). I'm running a few Steam Team Fortress 2 (TF2) idle accounts to acquire items for the production of metal.
I've set up a few bash scripts to connect each account a couple of hours a day through the night. What I've found over the last couple of years that various things will cause the automatic account logins to fail. Which I wouldn't normally notice until I decide to look at the server, which I do rarely.
So I thought one way to ensure thing were working correctly would be to write a script that would log into each account (say daily) and list/count the number items it has. Log it have something like Splunk pick it up (which I already have running for other stuff).
So after that long winded explanation, my question is, does anyone know how to write a script that can retrieve the item information from a TF2 account. My current bash scripts can perform the log in to Steam and can start up TF2, but I have no idea if that is the correct/best way to retrieve item info or even if I can be done from the same bash script used to log in.
Happy to use any language, but do have a fondness for Python.
Thanks.
Valve has released a web api which provides a flexible way to query your items from outside the game. First, grab an api key by following the instructions at http://steamcommunity.com/dev.
Next, in your script, fetch http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=API_KEY&steamid=STEAMID where API_KEY and STEAMID are your api key and 64-bit steam id respectively. This returns a JSON file which contains a list of all the items in your inventory. Just grab the size of the items array.

Exporting data from dev_appserver

I'm testing a schema change over two versions of my app. I used version 1 to generate test data, and now I'd like to take that data into version 2 to run and test the converter. This is easy enough to do live on appengine, since the datastore stays persistent between versions, but I'm finding that local_db.bin does not survive from one version to the next (maybe this is because the version of the sdk also changes between versions).
I'd like to use appcfg.py to download_data from dev_appserver and then upload_data to the new version, but it seems to be asking me to download each kind of entity individually ("Kind stats are not available on dev_appserver.").
I can write a script that iterates through all of my kinds to use download_ and upload_data. Is there an easier way to transfer data between instances of the dev server?
One unelegant solution:
bash script to pump data out:
KINDS="Assessment AssessmentScore Course GradingPeriod GradingPolicy OverallGradeDefinition Standard StandardTag User"
for KIND in $KINDS
do
echo "ugh" | appcfg.py download_data --filename=$KIND --kind=$KIND -email=blagh --url=http://localhost:8888/remote_api --passin --application=myapp
sleep 5
done
And a corresponding script with upload_data to pump it back in. Getting pretty kludgy when you're using bash to drive python to drive http requests to your java app!

Scheduling a time in the future to send an email in Java or Python

I'm writing an application and I'd like it to somehow schedule an email to be sent at a later date (likely an hour after it is run). The programming language will be Python or Java.
Any open-source tools available for that purpose?
EDIT: I forgot to mention it's to be run after a test run, so the application will already be down and I believe the Quartz solution wouldn't work. Would this be possible?
Ideally, I'd like to hear that SMTP protocol has some hidden stuff that allows this, and would just require adding some flag to the message and email providers would interpret as to having to send them later.
Quartz Scheduler can be user for this kind of asynchronous jobs.
Quartz is a great Java library for functions that you want to run at a certain time, after a certain time interval, etc.
There is also the Timer class in the JDK.
If you are to use Java, try Quartz, an open source job scheduling framework.
You can build the actual email to send, using JavaMail (with attachments and all), save it to disk, and then delegate a "mail foo#bar.com < textfilefromjavamail" to the Linux batch system.
There is an "at" command which will most likely do exactly what you want.
I don't think standard SMTP protocol has such a feature, so if you want to be platform-independent, you will have to search for another solution.
How about writing your message to a queue (local database, for example) with a timestamp and then have some program watching it periodically and send pending emails out?
Is the delay an exact timedelta or is it "1-2 hours later"? If it is the latter, than you can have an hourly job (cronjob starting every hour or a background job sleeping for an hour), which would then send out the emails.
Answer 1:
In Python, use threading.Timer to schedule in the future; use smtplib to send an email. No external library needed.
Answer 2:
Sounds like you want the sending program to quit rather than having it wait in the background. You may use cron for this. Alternative just use the unix command sleep and mail:
$ { sleep 3600; echo "hello world" | mail -s the-subject destination-email; } &
P.S. I don't believe SMTP have anything for you in this case. You are really looking for an MTA that has scheduling feature. Though I'm not familiar with it to make a recommendation.

schedule java program

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.

Categories