Activity and Status Tracking
A lot of our application runs on jobs that run regularly. They work, they don't. As such, we need to
be able to track these jobs and make sure they complete
notify a user of the system if they need to perform some action on behalf of the system (reauthenticate, etc.)
In addition, we also want to, as much as possible, architect a solution that is immutable--so we don't have to have a lot or retrieve/update/push_back cycles in our app, which decrease performance.
To that end, we have
a standard mixin that can be mixed into any class: ActivityStatusable.
a class that checks the last time something has run successfully or errored (using the Activity table)
A immutable class/table (Activity) that keeps track of all the "goings on" in the system. This activity is queried by the front end to show the User what's going on in the system.
Structure of an Activity
An activity has basically a key, and a value. The key is a string, and supports a "x.y" type structure similar to StatsD. By default, depending on the way you make the Activity, it might have an "action." on the front of it. But, the whole idea here is that this is flexible enough for you to put a status update for whatever makes sense.
For example, let's say you are using a Service/OAuth account in our system. When you reconnect to it and validate that its OK, you could add an status update to this:
service.action_status_update('authentication.authenticated', true, 're-authenticated successfully')
What might be confusing is the difference between an 'action' an an activity. The only real difference is that the action is prepended to the key. So, "action.sync" is an action, where "sync" is an update/activity. In practice, there is no difference between these.
There are two other interesting fields on the Activity record: system, and private. If the item is set to system, then its considered a system activity. These may or may not be shown to the end user. If the record is set to private, it should not be shown to the end subscriber.
ActivityStatusable
The ActivityStatusable mixin can be mixed into virtually any object. It provides a number of methods you can use to track things going on in the system. It has a number of helper methods that help you make activity records.
Last updated