I'm wondering what would be the best solution for such requirements?
Requirements:
There's an entity Label (the label is assigned to a product, ex. New, Sale, etc., and shown on the Product Listing Page) that could have a date range when it should be shown. In front, there's a varnish cache and we need to notify varnish (send purge tags) when the label should become visible (when date_from starts) and when the label should become invisible (when date_to starts).
The problem is that if I implement the cron job without any state then I do not know if the purge was already sent or not. I thought about a solution when I have an extra flag like is_showing=true/false, but maybe there's a better way?
Related
i have created a booking system which synchronizes with Google Calendar every 5 minutes and also truncates and old data and fetches new one from calendar, this process takes about 2-3 seconds.
What i want to do is, when the event to fetch data from Google Calendar fires, i want to disable access to the route of the booking system for these 2-3 seconds then enable it again when the event ends, i want to do this because it truncates the old data and fetches new one, so if a person is looking at the booking system this 2-3 seconds all the book schedule times will be free and i don't want this to happen.
Is this kind of thing possible?
Thanks and regards!
Well, my suggestion is to create a new field in your users table something like : is_google_sync_active and route middleware.
Then just before you will start sync. you change that field to true and in your new middleware you may check whether your sync. is active or not, then when your sync. ends you just change the value of field again to false. So, every time when user tries to pass to your sync route he will be passing your middleware which wil handle all job.
In addition, you can redirect user to page which shows status or progress if the sync. is processing.
I'm new to Oracle Forms.
I want to be sure that an item considered "valid" as soon as inputed, at time T0 (thru When-validate-item trigger), is still valid when the relevant row is inserted (or updated) and committed at time T1, where T1-T0 could be, say, a long coffee time, during which the system status may have changed so as to invalidate the item.
I thought about coding specific item-level program unit to be called both by WVI trigger and by a higher level trigger. Which one would be best?
Is this double check a common practice in Oracle Forms?
Note: I need to double-ckeck both in case of form layouts and in master-detail layouts.
Thank you.
You don't need to double-check on normal validation. Then a when-validate-item trigger will be enough to make sure it is valid. If you need to check a field that needs also a value in another field, for example a person is a firm it needs only a lastname otherwise it needs a first and a lastname then you could use the when-validate-record trigger to check this.
If your data depends on the system date or other data that might be inserted/updated in the time between validate and commit. You should place your validation on the pre-insert and pre-update trigger. Then it will always fire just before the insert or update.
I don't know how exactly handle this situation. I have a directory where I count the pageviews for each item. For authenticated users I only count as new pageview after a delay of 200 seconds between requests. For unauthenticated users I use the IP and also 200 seconds of delay.
I use a redis SETEX to verify and then the key will expire after 200 seconds. If the key doesn't exist, then insert a new page view.
Something like this
item_id:user_id (authenticated users)
item_id:ip (unauthenticated users)
Well, this works fine until a user try to increment intentionally the page views for a specific item. I have almost 3000 views for a specific item only yesterday (in last year the page has only 150 views...). So, he created some bot to visit the page with a delay to avoid my validation.
I need to register legit pageviews, but I need to avoid the type of fraud. Any idea?
As far as I know, the best way for handling bots is a way like Google Analytics.
Google Analytics works by inserting a JavaScript snippet into the
header of your website. This snippet counts a page view whenever a
visitor triggers that JavaScript, and most bots do not process
JavaScript.
You can integrate some kind of CAPTCHA in your application to limit the number of times a user can view the page within a specific amount of time.
Upon a set number of views within a given duration (say, 20 views in under 3 minutes) from the same user or IP, make them verify the CAPTCHA each subsequent time they try to view the page.
Issue a Token for every page view request. Store the token in the Cookie.
User your already available IP or USER_ID as a filtering mechanism.
After page loaded, User the token, old_token from the cookie, Operating System, Browser Name and IP / User_ID to validate the request.
Give two different timings, like 200 second expiration time and 3600 seconds of grace time, if any of the above data matches within the grace time, don't count the page view.
You can also extend this by keeping track of page views within grace time and create some methods to validate pageview request.
I usually register the Request Time together with the Request to measure the Visit Frequency and the Visiter Count per certain Time Span.
When you register all the Request that come in with with the item_id, user_id, ip and timestamp you can afterwards process the Registers by grouping them by user_id, ip and timestamp.
That way you can find out the amount of Hits per Second and identify and exclude those who clear surpass the normal Activity Pattern without loosing Data.
Often I use the Web Service Logs to generate Statistics about Visit Frequency to certain URLs on a hourly, daily or even monthly basis.
i am using Spring/Hibernate/ZK. In one tab i get object from DB for editing by user, but second user can open the same tab and the same object for editing . I want to informed second user whit message like "This object is аlready open" and hide buttons for save.Тhus second user can see current data from DB to this object but can`t edint him.Is there a way to check session for this object or another way to do that.
The other answers mostly look at the database, but if all users use the same zk application to access the database, you could keep track of opened objects in the Composer or ViewModel (depending whether you use MVC or MVVM; I'll just call it controller).
Your controller would need a static list of objects that are currently modified. If a user requests to open an object that is not in the list, everything is fine and your controller enables the fields and save button. Otherwise, those are disabled and/or you display a message.
The tricky part is clearing objects from that list. If a user presses the save button, you just remove the object from the list. But what if the user doesn't and just closes the tab or their session just times out? In this case you need a callback, or a mechanism that regularly checks whether the screen is still open.
You could achieve this by adding a zk timer to the tab that pings every now and then and updates the timestamp in your static list (so make it a map). If a new user tries to edit the object, check how old the last timestamp is. If it is old enough (i.e. the previous user saved it or abandoned the screen), allow them to edit it.
Still, you have to think about what to do if a user just keeps the screen open. How long are they allowed to keep the lock on the object? This is an issue in Microsoft Office as well. If multiple users try to open an Excel file from a network location, the first one gets to lock and the others cannot save until that user saves.
You may have additional field which indicates that column is being edited. When first user starts work, the field would be updated. The second user would query object with 'on hold' status and your code would handle this.
Other way - use Hibernate #Version field in your entity. It holds object version which is incremented after every update operation. If second user would save object after first one already saved, it would throw OptimisticLockException which you could handle in your code. More about optimistic and pesimistic locking: Chapter 5. Locking. Related discussions: Hibernate Automatic Versioning and When to use #Version and #Audited in Hibernate?
The best solution is to use Optimistic Concurrency Control with Versioning and when Hibernate throws Concurrency Update issue due to same row is being updated in two transaction then use one of below strategy
First Wins Strategy
Last Wins Strategy
Merge Conflicting Update Strategy
First Wins Strategy is not good solution as it leads to lost update and user will get frustrated that all his work is lost.
By Last Wins Strategy one of user will get error message that you are working on Stale data and start your transaction again . By this way also user can get frustrated due to fact that now again he need to restart operation from beginning but his changes will not lost.
Instead go with Merge conflicting Update Strategy, when Hibernate throws Stale object exception reload screen with new data and user will see updated result and allow him to proceed with latest data. In this user changes will not loss and user will not get error message , just his screen reloads with fresh data and he can decide whether to proceed or not .
You can take example any e-commerce site and you will get one of result of either Last Wins Strategy or Merge Conflicting Update Strategy. Two user can start to by one item but one of user will get message in last screen that item is not stock.
I got a screen (block) in which users make requests for a specific product and I validate the number of items available in the database at the moment of the request, before they commit, which is suposed to reduce the existence ot the item requested.
The problem I'm facing is... if several users are making the request at the same time they all get the existence available before a complete request has been done by a user. So when another user makes the request, the existence in the datase is unreal for that particular user.
I think of validating the existence of the product again before commiting the request to the database, and display a message to the user that the existence has chaged since the he first logged in. I don't know if that is a good solution. I need your expiience in this type of situation.
How can I control the existence of an item while several users are making requests at the same time?
I just need the basic idea so I can continue with the code.I think the problem is independent on language I am using.
I'm not sure this is really the answer to your question as I never used Oracle Form. But, generally speaking, to face that kind of issue, you should use atomic test and set queries. Sounds scary, isn't it? But really simple:
Say at a given point, one of your users saw that inventory:
SELECT * FROM INVENTORY WHERE PRODUCT='LEMON';
ID PRODUCT QTY
2 LEMON 200
There was 200 lemons in stock at the time of the SELECT query. But maybe, those has been sold out by now. Maybe. Maybe not.
If the user seeing the 200 lemons decides to check out, say 100 of them. You can only do that if there is still 100 or more lemon at the time of UPDATE. Concretely you will write:
UPDATE INVENTORY
SET QTY=QTY-100
WHERE PRODUCT='LEMON' AND QTY >= 100;
That way, you only update your table if enough lemon left at that time. Since Oracle ensure that only one statement can update a row at a time, all concurrent requests to update that row are handled sequentially. In addition, by the use of the WHERE ... QTY >= 100 Oracle will check the number of items remaining at UPDATE time.
You have to be prepared (and you must check!) the outcome of the statement to see if one row was updated or not. It no row was updated, that means there wasn't no longer enough lemons in stock at the time of update.