How to create an auto task schedule ios notification based on an event with mysql data - mysql

I have a problem related to automatic task scheduling.
Currently i am able to find out when my customer has last credited his account, how am i able to find out whether he will pay anything in the next 3 days?
So if no payment has been made in the next three days for any customer, to automatically alert me preferably by a notification directly to my ipad.
I dont want myself to open the app for checks to be done only when i log in, because then if i jump on my application 6 days later, i could have had a customer that hasnt paid in 6 days when the app should have alerted me on the 3rd day so i could ring my customer up to deal with the matter.
I need to work in this matter due to the structure of my application and business.
I am able to monitor everything else but need some insight on how I can go about doing this. the current notification system inside the phone only fires based on time, and I cannot do interval checks where maybe i could run a background task, if that would work then i would have done it like that but thats not the case.
Pavan

If I understand your question correctly, you should compute the interval of the event that you want and post a wake-up timer that is that period of time from "now." If you need it through the notification center, then just handle it silently and clear it from the notifications.
Based on the discussion below:
You will need a little bit of server work. APNS looks complicated, but it really has very few moving parts -- especially if it is a private App. What system component is keeping an eye on Amazon? Do you have an App or web server? For example, if I were to poke a record into your system (purchased services) what workflow is triggered to notify Accounting to process an invoice and collections at a later date? Am I making any sense of your system architecture?
Perfect - you are done. You have all the system components you need and the rest is coding. The server app processes the accounts DB and finds new entries. If found, it publishes a record ID to the APNS server (Apple owns this server). You write code to register to receive the push-notification (subscriber). When you get a push, that will wake up your registered app with the record ID (and some other subscription stuff for bookkeeping -- but you are the only subscriber and only subscribing to one DB table -- so you can largely ignore. Now turn around and query based on that record. Done!

Related

MS Access: Multi-User Application: send msgbox to specific user

I don't know if my idea is possible to solve with MS Access. The requirement:
I have one centralized DATA-database and several Client-Databases. It will be used to maintain a rescue team in our company. Each one has to press a button in his client and in the reception client is visible who is available in case of an emergency.
It even shows who is in which corner of the building the rescue person is.
Now, it's in human nature that in evening People forget to logout. Plan is to define a usual end of work time. The reception client verifies every 5 Minute if someone reaches his end of work time and can set him as out of office.
Problem is, perhaps Mr. X works today not until 17h as usuall - today he is available until 20h.
So, a message should Pop up 15 Min before his end-of work and ask him if he goes by time or not. If he answers to work longer, a flag should remove him from this function today.
Solution is almost 70% developped. Problem is now the little point, how to pop-up the message to the right user. One Idea is to check a message table if there is a message for him.
But, i don't like to make to much LAN traffic... if each client ask every 5 minutes the DATA DB if there is a message for him.
Has some one an idea?
Best regards
Roland
Polling a single table every 5 minutes should generate virtually no load. I've used a similar solution that polls every minute without any trouble on a networked database with ~20 users.
You can, of course, pull in these messages once, since they will fire at a set time, and then just raise them at that time.
You can just have a hidden form that's bound to a specific table, uses a filter on the username, and requery every x seconds, tests if there's a message ready, and then displays it.
Alternatively, you can pull in messages once, and have a hidden form that checks on timer if it's time to raise that message.

How to sync the database with the microservices (and the new one)?

I'm developing a website with the microservice architecture, and each of the service owns a database. The database stores the data which the microservice needs.
Post, Video services need the user information, so both of the services subscribed to the NEW_USER_EVENT.
The NEW_USER_EVENT will be triggered when there's a new user registered.
Once the services received the NEW_USER_EVENT, they put the incoming user information to each of their own database. So they can do things without asking the User service.
So far so good. But here comes the question:
What if I'm going to create a new service? How do I get the registered user informations and put them in the new service?
Maybe I can get the informations from the existing services. But the events are pushed by the messaging queue (NSQ).
If I'm going to copy the data from one of the microservices, how do I make sure which service has the latest user informations? (Because some services haven't received the latest event)
Read More:
The Hardest Part About Microservices: Your Data
Intro to Microservices, Part 4: Dependencies and Data Sharing
What if I'm going to create a new service? How do I get the registered user informations and put them in the new service?
You have to replay all events to which this new service is subscribed from the beginning of time (you should have an "event store" that keeps all events already happened in your application). Also, you can put a bit smarter logic when replaying events by starting from the most recent ones and going back in time. In this way, you will be able to restore most valuable data first. Just be careful to handle interdependent events correctly.
Data source: The events are pushed by the messaging queue(NSQ), If I'm going to copy the data from one of the microservices, how do I make sure the copy source has the latest user informations?
You are not talking about doing backups, right?
Aside from backups, in the event-driven systems people usually don't copy the data in a classical way, row by row. Instead, they just replaying events from event store from the beginning of time and feeding those events to the event handlers for the new service (or new instance). As a result, new service eventually becomes consistent with the other parts of the system.

Notify Users When Record Hasn't Been Updated in X Amount of Time

I'm working on a Rails 3.2 application where users create, read and update multiple kinds of reports. We use MySQL and Redis.
I would like to notify users when one of their reports hasn't been updated in the previous X months by showing them notifications on their profile/dashboard page in the browser.
I would prefer to do this asynchronously.
At some point, I would also like to have live, in-app notifications so users can be notified when a report they're watching has been updated or someone likes their report. Conceptually, I was contemplating the best way of going about doing this...
A cron job that runs a SQL query and retrieves all reports that have update_at fields older than 3 months, and creates a notification record linked to that user and report. A new notification record will be created only if user didn't have an existing notification.
A background job, using something like Resque that checks the database periodically throughout the day. Notifications are stored in a queue. This seems like it would scale better into a more robust, in-app notifications feature.
Are these my only two options? Is there a better asynchronous way to listen to the database, and notify a user when one of their records hasn't been updated in 3 months? Is some implementation of websockets necessary here?
I don't believe you necessarily need to use CPU cycles with some always-running background job, but that depends on how powerful you want these notifications to be. If you want them to be real-time, and you plan on using a publisher-subscriber model in the future then I'd consider a redis + node server setup.
The complexity of websockets means more implementation time. Will that extra time spent really benefit you? If it's very important that your notifications be asynchronous and real-time, like exchanging messages in a chat app or getting pop-up notifications on Facebook, then this is the right choice.
However, if all you really want to do is let users know when their reports are past a certain age, when they request their profile page, a cron that runs every couple of hours will be much easier to implement. You could even use Google Analytics to get a feel for when users are putting the heaviest burden on your app, and schedule the job around that.
First, create a rake task that completes the behavior your described above--check for old reports and create notifications. Put that in your app's lib/tasks directory. And then write a cron job like so:
$ 0 6,12,18 * * * cd /path/to/app && bundle exec rake task_name
This task will run 3x a day, at 6am, 12pm and 6pm.
From there, if you want to create an activity feed for your users, you could also implement a synchronous pub-sub solution pretty simply. E.g., User A subscribes to User B's reports, User B publishes a new report, after_save callback to create a notification for User A. This will be slower, it won't be live, but if it's a small app and this feature isn't a core part, then this makes better use of your time than the other options.

Move information-resource stored in the database tables with two step using 'reservation'

I need to architect a database and service, I have resource that I need to deliver to the users. And the delivery takes some time or requires user to do some more job.
These are the tables I store information into.
Table - Description
_______________________
R - to store resources
RESERVE - to reserve requested resources
HACK - to track some requests that couldn`t be made with my client application (statistics)
FAIL - to track requests that can`t be resolved, but the user isn't guilty (statistics)
SUCCESS - to track successfully delivery (statistics)
The first step when a user requests resouce
IF (condition1 is true - user have the right to request resource) THEN
IF (i've successfully RESERVE-d resource and commited the transaction) THEN
nothing to do more
ELSE
save request into FAIL
ELSE
save request into HACK
Then the second step
IF (condition2 is true - user done his job and requests the reserved resource) THEN
IF (the resource delivered successfully) THEN
save request into SUCCESS
ELSE
save request into FAIL
depending on application logic move resource from RESERVE to R or not
ELSE
save request into HACK, contact to the user,
if this is really a hacker move resource from RESERVE to R
This is how I think to implement the system. I've stored transactions into the procedures. But the main application logic, where I decide which procedure to call are done in the application/service layer.
Am I on a right way, is such code division between the db and the service layers normal? Your experienced opinions are very important.
Clarifying and answering to RecentCoin's questions.
The difference between the HACK and FAIL tables are that I store more information in the HACK table, like user IP and XFF. I`m not going to penalize each user that appeared in that table. There can be 2 reasons that a user(request) is tracked as a hack. The first is that I have a bug (mainly in the client app) and this will help me to fix them. The second is that someone does manually requests, and tries to bypass the rules. If he tries 'harder' I'll be able to take some precautions.
The separation of the reserve and the success tables has these reasons.
2.1. I use reserve table in some transactions and queries without using the success table, so I can lock them separately.
2.2. The data stored in success will not slow down my queries, wile I'm querying the reserve table.
2.3. The success table is kind of a log for statistics, that I can delete or move to other database for future analyse.
2.4. I delete the rows from the reserve after I move them to the success table. So I can evaluate approximately the max rows count in that table, because I have max limit for reservations for each user.
The points 2.3 and 2.4 could be achieved too by keeping in one table.
So are the reasons 2.1 and 2.2 enough good to keep the data separately?
The resource "delivered successfully" mean that the admin and the service are done everything they could do successfully, if they couldn't then the reservation fails
4 and 6. The restrictions and right are simple, they are like city and country restrictions, The users are 'flat', don't have any roles or hierarchy.
I have some tables to store users and their information. I don't have LDAP or AD.
You're going in the right direction, but there are some other things that need to be more clearly thought out.
You're going to have to define what constitutes a "hack" vs a "fail". Especially with new systems, users get confused and it's pretty easy for them to make honest mistakes. This seems like something you want to penalize them for in some fashion so I'd be extremely careful with this.
You will want to consider having "reserve" and "success" be equivalent. Why store the same record twice? You should have a really compelling reason do that.
You will need to define "delivered successfully" since that could be anything from an entry in a calendar to getting more pens and post notes.
You will want to define your resources as well as which user(s) have rights to them. For example, you may have a conference room that only managers are allowed to book, but you might want to include the managers' administrative assistants in that list since they would be booking the room for the manager(s).
Do you have a database of users? LDAP or Active Directory or will you need to create all of that yourself? If you do have LDAP or AD, can use something like SAML?
6.You are going to want to consider how you want to assign those rights. Will they be group based where group membership confers the rights to reserve, request, or use a given thing? For example, you may only want architects printing to the large format printer.

How to set a global clock in a servlet container to check expiration date in database

I'm developing this website which works like a kind of auction for specific kind of items.
The website will be developed using pure jsp and servlets.
Basically the items that the sellers will post on the site have an expiry date, after that date "1 minute after midnight of the selected expiry date" the product will be assigned to the highest offering user or registered as unsold.
The items will be stored in a MySQL database with a Date column.
I need to find a way to automatically find out when an auction for an item is expired, i was thinking of a Timer object within the servlet container that every day one minute after midnight sends a query to the DB to check which auction is expired and to take an action accordingly.
Before to start working on it i wanted to check rather there are better "known" options.
Any idea?
Thank you
Quartz Scheduler are better suited.
Quartz is a full-featured, open source job scheduling service that can
be integrated with, or used along side virtually any Java EE or Java
SE application - from the smallest stand-alone application to the
largest e-commerce system. Quartz can be used to create simple or
complex schedules for executing tens, hundreds, or even
tens-of-thousands of jobs; jobs whose tasks are defined as standard
Java components that may execute virtually anything you may program
them to do. The Quartz Scheduler includes many enterprise-class
features, such as JTA transactions and clustering.