Automated Heroku PostgreSQL Updates without Client Request - sql

I am new to web development. I am building a simple text based web game. I am using heroku and postgresql. I have sql table for users and their coin amount(their earnings).
I can receive/transmit data from this database by using requests made from players. However what I want to achieve is to automate the coin addition to each users account.
So let's say at the beginning of each hour, I want to add 15 coins to each user. How can I possible achieve this kind of automation with heroku and postgresql ?
I tried searching for almost an hour, but I wasn't even able to find the name of this process :(

While you could schedule this (as sonnyhe notes), it's probably better not to.
Instead, just update the value when you're updating their balance for some other reason, by adding the difference between the time you last added coins and the current time, extracting the hours, and multiplying by 15.
If the user asks to just view the balance, all you need to do is display its last stored value plus the hours since then * 15.
That way you're not doing lots of unnecessary updates and causing unnecessary load.

Here is a gem you can look into.
Just include the gem rufus-scheduler in your gemfile.
The you can set something up in you config/initializer/scheduler.rb
scheduler.every '15m' do
# Update all coins with 15 more.
end

Related

Recommendations for multiple migration runs?

Could anyone provide any best practices about multiple migration runs? Moving from TFS 2017.3.1 to Azure DevOps Service. Dealing with a fair number of work items (32k). Of course, TSTU throttling is making the run take a long time, so I was thinking of pushing what I could up front, then a second pass to pick up the new work items since the first big push. So...enabling UpdateSourceReflectedId would set the ReflectedWorkItemId on the source items that have already been migrated. But what happens if someone changes a work item that has already been pushed? Would the history delta get picked up? How is that typically resolved...I was thinking maybe a Querybit like: ReflectedWorkItemId <> '' and ChangedDate > (last run time), but is that necessary? Those already exist on target...would ReplayRevisions pick up only the missing changes? TIA...
I usually do the following for large runs:
Open work items edited in last 90 days
Closed work items edited in last 90 days
open out to more days in chunks
The important thing to note is that links are created only when both ends of the link exist.
After a long run you can then rerun "edited in last month" to bring any changes a cross.
Changes to avoid in the Source:
changing work item type
moving work item between team project
We handle these, but loosly.

How do I disable "activities" for a custom module on SugarCRM 6.5+ 7+

The title is pretty clear but again: How do I disable "activities" for a custom module on SugarCRM 6.5+ 7+
I have a module containing millions of records and activities has been slowing it down to a breaking point. I managed to stop the activities through some hacking (deleting entries from the cache folder) but I would like to know how to do it the right way so on repair&rebuild + etc things will be normal/ok.
//edit1:
I'm happy to completely disable activities for a limited period of time while my script runs and then enable it again right after if that is possible.
Well, I figured out how to disable activities (activity stream, known in the past as sugar feed I think).
As my problem was running a script on 100k records etc disabling the whole activity stream temporarily in the beginning of the script and then turning it back on in the end was sufficient.
It's quite simple and it feels like an embarrassment I didn't look into the activity stream's source before since in order to disable it a simple:
Activity::disable();
does the job and to turn it back on:
Activity::enable();
There is also a "blacklist" array in the source etc but 1- It didn't solve the problem and 2- It's clearly not upgrade safe etc.

Webmatrix - Regularly run a SQL query

i have an SQL query (shown below) that i need to run on a regular basis:
db.execute("UPDATE property_info SET IsActive=false WHERE ExpiryDate > #0", CurrentDate);
This query is basically intended to check ALL properties, and to see whether or not they are past their expiration date. If they are, then it will automatically set the property to Inactive. Because "CurrentDate" is a rolling window, i want to re-run this query automatically, probably every day.
Is this something i should be using a stored procedure for?
Any suggestions on the best way to achieve this without any user interaction?
One simple way to achieve this would be to add the line of code to _PageStart.cshtml in the root of your project. This will make it execute every time any page on the site is executed. That is probably massively overkill for something that, by the looks of it, only needs to be checked once a day or so. To alleviate this you could employ a simple DateTime stamp in the Application collection to make sure it only runs a maximum of once every day or so (or tune the interval as appropriate for your needs). This is in no way a solution for fully scheduled code execution, but it may well serve your purposes (and your budget).

Simulaneous changes to objects

I'm in the process of developing an app that manages the inventory in a shop. I assume that there could be potentially more than one user working with the app and therefore a scenario where both could reserver for checkout the same item (but for two different recipients is a likely one.
Are there any gems that or techniques someone could recommend that could help with this?
When the users create a new order they get the list of objects that are not reserved (this is a rental shop) but if one leaves the form open for a bit, without making the reservation, someone else still sees the item as available.
Can anyone offer advice about this? Hope the question is not too vague.
Is callbacks the way to go, by creating a before_save validation?
Thank you!
You can use a gem like delayed_job where you can schedule a job to be run at certain time, in this case, after a certain timeout.
You can then schedule a job which removes the reservation status on an item. If the user is successful in reserving the item, the delayed job needs to be deleted.
To delete the item from this activerecord table, you can find it based on the table attributes specified here.

How to implement a trial period for a objective c/cocoa mac osx app?

I'm getting started with Objective C and Cocoa on Mac and i would like to develop a app that will have a trial period of 30 days for example like most of the apps have.
How can this be implemented on Mac OSX? Do i store somewhere the installation date and then on each run i check for that? Or what is the general way of achieving this?
That is certainly one way to check the expiry of a trial, but I've found that implementing time based trials can be troublesome when dealing with slightly cleverer users.
If you use a time trial (i.e. 30 days) how do you check the time? You can store the time that the app was installed, and you can read the current time to work out the difference, but how can you guarantee the time(s) you are reading is correct. The user may have edited one or both of these values. (By changing your stored value if it's not encrypted or by changing the system time).
You could use the Internet to verify the time, but what would you do if the user isn't connected to the Internet?
I'm sure there will be more sophisticated ways of checking how long the user has had the program installed, but I'm afraid I can't enlighten you to any.
I'd consider one of the alternatives methods of providing a trial:
Number of times the app has been started - (take into account that your app may crash, or the user may keep the app open). You may wish to count instead, the number of days on which the app has been opened and allow the user to open the app on 15 different days.
Restricted Content - Make a separate target for your app with less content. This is a safer way to ensure that the user can't work around your restrictions, but it's also more work for them to install a separate version. Consider that you may lose some sales.