Charging of parcels

32 views
Skip to first unread message

Edson

unread,
May 30, 2012, 7:57:26 AM5/30/12
to hobo...@googlegroups.com
Hi folks,

What's the best approach i must have to design a system where i have an bank account and loans. The loans must be charged by parcels. For example: if i give some credit to a person (1000 USD) then i want to charge him 10 parcels, 1 per month in 10 month. So i need i way to Decrease the parcels as they are being paid.

Could someone give me a tip on this approach
?

Thank You all,

Edson

Bob Sleys

unread,
May 30, 2012, 8:05:54 AM5/30/12
to hobo...@googlegroups.com
I'd look into a rake task that could be run via cron job.  Just make sure the rake task can handle things properly if for some reason the cron job doesn't run for some reason.  IE I'd set up the cron job to run once a day and have it run the rake task and log the results. If the cron job doesn't run for some reason you need the rake task to be able to catch up and get things in balance again.  You could also setup a 2nd cron job to monitor the first one by looking at the log file.  The 2nd job would e-mail you if anything went wrong with the first one. ie errors in the log or even nothing in the log as in it didn't run at all.

Bob

Edson

unread,
May 30, 2012, 12:48:45 PM5/30/12
to hobo...@googlegroups.com
I'm sorry Bob, but is that msg for me ?

If yes i didn't understand.

Thank You,

Edson

Bob Sleys

unread,
May 30, 2012, 2:01:34 PM5/30/12
to hobo...@googlegroups.com
What you need is a job to run to calculate the parcels each day, week, month, whatever time period you need.  This job needs to run say once a day and find all accounts that owe parcels and decrease the amount that is owed.  Sorry I don't quite understand your parcels and charging system but it's pretty obviousness you need a job to run every x time frame, do a calculation and save those changes to the database.  Ruby and rails has no default built in scheduling of jobs to be run at specific time frames but all operating systems have a job scheduler. in linux the most common OS ruby on rails apps are run uses cron to schedule and run jobs. So its a natural fit to schedule your job to do that calculations.  The next questions is what should it execute or run.  Rails has rake tasks.  These tasks are the same ones you use to migrate the database, build a default app etc.  You can write your own tasks. Here is one of many tutorials on rake tasks  http://jasonseifer.com/2010/04/06/rake-tutorial .  So to solve your problems I'd personally write a rake task that could be run once a day that found all accounts that needed to be charged parcels, do the calculation and make any database changes and use a cron task to run that rake task each day at a specific time.  I'd probably also write a simple shell script to monitor the first cron job and rake task to make sure everything is working as it should and notify me via an e-mail if something is wrong, say the task didn't run or encountered an error.  I'd than setup a second cron job to run a bit after the first one to run the shell script.  Basically a simple monitoring routine so if something goes wrong I'd get an e-mail letting me know.

Bob

Edson

unread,
Jun 4, 2012, 9:52:39 AM6/4/12
to hobo...@googlegroups.com
Hello Bob,

Thank you for the BIG tip.

i did not answer before because i went out on travel.

thank you once again,

edson

Edson

unread,
Jun 4, 2012, 10:43:11 AM6/4/12
to hobo...@googlegroups.com
Hello Bob.

But in term of models what is the best approuch:

Have a client that have an account and account have parcels and client have parcels through account?

thanks in advance,

best regards,

edson
Reply all
Reply to author
Forward
0 new messages