system-timer | Reliable Ruby timeouts for M.R.I. 1.8
kandi X-RAY | system-timer Summary
kandi X-RAY | system-timer Summary
System Timer, a timer based on underlying SIGALRM system timers, is a solution to Ruby processes which hang beyond the time limit when accessing external resources. This is useful when timeout.rb, which, on M.R.I 1.8, relies on green threads, does not work consistently.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Returns the next deadline for the current timer
- Trigger the next timer for the given timer
- Logs the timeout after a timeout
- register a thread
- register a timer
- Logs out of a registered timer .
- Returns the next trigger for the trigger
- Calculates the next trigger for the given interval .
- Cancel a registered timer
system-timer Key Features
system-timer Examples and Code Snippets
Community Discussions
Trending Discussions on system-timer
QUESTION
Top note: Per comments I could guess all are working solutions with this note Indeed in my application I am trying to combine them. By the way before downvoting you could ask me for details.
Top note 2: By the way, as SO is different from MSO downvotes or close votes encourages deleting question, I won't, otherwise all valuable comments and answer will be deleted. Here is a place to help and try to understand each other
Here is most basic of 4 different implemantations of linqpad codes. Except first all others gives desired output.
Can you explain details for them?
As I have many timers in my application I need to manage and synchronize, in complete code which is to best use and what are the pro/cons of alternative solutions
Without Neither SynchronizingObject nor timer stop/start nor lock
...ANSWER
Answered 2017-Nov-07 at 17:19The 4th solution (
lock
) is a dangerous one. Since theElapsed
event will be raised on aThreadPool
thread each time and you might potentially block many of them simultaneously, this could cause theThreadPool
to grow (with all the consequences). So that solution is a bad one.The 3rd solution (start/stop) will process the events not at the rate set by the timer, but rather at the rate that depends on how much time does each particular action take. So it may "skip" many events. This solution is like a "frame drop" in video streaming.
The 2nd solution will enqueue all the actions and won't skip them. It's potentially dangerous when the action's processing time is (almost always) longer than the timer interval. The queue will only grow causing an
OutOfMemoryException
at some time. This solution is like a "frame buffer" in video streaming.The 1st one should be deleted, there are only issues with that.
So you should choose between the 2nd and the 3rd solution depending on what is of importance for your use case: a reliable processing of all incoming events or a processing with a maximal possible throughput (rate).
QUESTION
I'm using System.Timers.Timer to backup my SQL Server Express Database once a day. It seems to work fine, most of the time. Occasionally, the ElapsedEventHandler gets called multiple times at 1 or 4 minute intervals. It should just be hit once a day. I have AutoReset as false and I call Start at the end of the ElapsedEventHandler. Also, possibly relevant is that I do recalculate the interval so that the timer always goes off as close to 1 am. as possible. The backing up of the database can take a few minutes, and if I didn't change the interval, the time might drift unacceptably. I mention this because these links suggest there might be a problem with resetting the interval:
See in particular the answers by Hans Passant
However, I don't see how I can avoid resetting the interval. Also, I looked into the code for System.Timers.Timer. It didn't seem like just resetting the interval would Start the timer again. I'm not opposed to using a different timer (System.Threading.Timer?) but I'd like to know what is going on first.
I've pasted all the code below. I would think the truly relevant part is the method: DatabaseBackupTimerOnElapsed
Finally, I'll mention that the program is sometimes stopped and restarted (if there are uncaught exceptions in other parts of the code). I would assume though that all timers are killed at the point of exiting the program even if Dispose is not called? That is Timers don't live on in the operating system?
EDIT I was requested to put down a small, complete, verifiable example. I do so here. I've kept the full example as someone might claim (quite correctly!) that I took out an important detail. I've run this code and have NOT seen the problem but then, it only happens very occasionally with the original code.
...ANSWER
Answered 2017-Jul-18 at 19:03I think the solution is overly complicated.
- The timer interval will fire the Elapsed event independent of when the fact that a previous run had finished or not, unless you explicitly stop the timer during the event. This should not be necessary. You could simply keep track of whether you are running or not when you enter the method.
Set the interval to 59999. This is a millisecond short of a minute. Then at entry in the event handler check if the current hour and minute correspond to the time when you want to backup.
QUESTION
Our app support team is suggesting to implement audit trail, extensive error logging and a new batch job to process some data internally. Before implementing this, I want to make changes in my use case diagram. I think audit trail must be an use case but not sure about the error logging. Should it be considered as an use case. This link http://www.umlchannel.com/en/uml/item/24-use-case-actor-system-timer is saying an use case sometimes may have NO actor. Can we consider error logging as an use case without an actor? Can I consider a batch job as an use case where batch scheduler as an actor?
Another clarification I need is : I know actor can be a person or another system. Can we consider an event (that interact with a solution through use case) as an actor?
...ANSWER
Answered 2017-Jan-31 at 12:38A use case must have an actor, since basically it just describes the added value for its actor. The author of the referenced article is simply wrong here.
P. 637 of the UML 2.5 specs:
Each UseCase specifies some behavior that a subject can perform in collaboration with one or more Actors.
...
A subject of a UseCase could be a system or any other element that may have behavior, such as a Component or Class. Each UseCase specifies a unit of useful functionality that the subject provides to its users
N.B.: Though the UML is the "true source", it's not a good read about use cases. Instead I highly recommend Bittner/Spence.
There are several ways to approach the Log error
"use case". One would be to use cases with
Log error
. But actually, there are a couple of drawbacks with this. Log error
might give additional value in the long term (system improvements and bug corrections), but it is not an a-priori added value. Also you would just clutter your use case diagrams.
A second way is to change the perspective and include the "system" itself as an actor. But this is an anti-pattern. So not recommended as well.
Finally, you could simply add a non-functional requirement to your system and just trace to the use cases which are relevant. This is what I'd recommend to do.
Your additional questions:
- A batch job is no use case, but a use case can be implemented as a batch job and the scheduler can be the actor.
- No, an event is an event and not an actor. An event can trigger a chain of actions being part of a use case.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install system-timer
On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page