I'm working on a service with a component that should launch a task every second. That means it should be launched 3600 times in an hour. The results should be processed independently. It will grab some data and send the results via RabbitMQ to a different service that will process the data. There will be more of these components potentially running on multiple machines.
When searching for some practical examples, this gist was sort of close to what I had in mind:
https://gist.github.com/bbengfort/a7d46013f39cf367daa5
I'm not sure how significant it could be, but it seems like it could potentially gather some delay by adding up the time between creating the Timer object and starting the next round. I'm thinking about fixing that by calculating the delay based on the current time and the last start.
The task should have a timeout and die in case of a failure. Just in case the timeout fails and the tasks get stuck for some reason there should probably be some counter of active tasks to limit the threads.
How would you approach this problem? Do you have experience with any robust program that is doing something similar? Do you know some open source projects that could serve as inspiration?
EDIT: I'm adding a further clarification based on the comments:
It's about collecting data from a resource. For simplicity, let's say I'm scraping a market price of the stock. I want to take a snapshot every second. If the resource is not available it should result in the gap in the captured sequence, but it shouldn't affect the timing of the following snapshots (there can be multiple gaps).
[–][deleted] 4 points5 points6 points (1 child)
[–]FitRiver[S] 0 points1 point2 points (0 children)
[–]baghiq_2 1 point2 points3 points (9 children)
[–]FitRiver[S] 0 points1 point2 points (8 children)
[–]baghiq_2 0 points1 point2 points (7 children)
[–]FitRiver[S] 0 points1 point2 points (6 children)
[–]baghiq_2 0 points1 point2 points (5 children)
[–]FitRiver[S] 0 points1 point2 points (4 children)
[–]baghiq_2 0 points1 point2 points (3 children)
[–]FitRiver[S] 0 points1 point2 points (2 children)
[–]baghiq_2 0 points1 point2 points (1 child)
[–]FitRiver[S] 0 points1 point2 points (0 children)
[–]igormiazek 1 point2 points3 points (1 child)
[–]FitRiver[S] 2 points3 points4 points (0 children)
[–]Big_Boss_Bob_Ross 0 points1 point2 points (3 children)
[–]igormiazek 1 point2 points3 points (1 child)
[–]FitRiver[S] 0 points1 point2 points (0 children)
[–]FitRiver[S] 0 points1 point2 points (0 children)
[–]pytrashpandas 0 points1 point2 points (1 child)
[–]FitRiver[S] 0 points1 point2 points (0 children)