-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Checkpoint model and Model replication methods
- Loading branch information
Showing
2 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Module Dependencies. | ||
*/ | ||
|
||
var Model = require('../loopback').Model | ||
, loopback = require('../loopback') | ||
, assert = require('assert'); | ||
|
||
/** | ||
* Properties | ||
*/ | ||
|
||
var properties = { | ||
id: {type: Number, generated: true, id: true}, | ||
time: {type: Number, generated: true, default: Date.now}, | ||
sourceId: {type: String} | ||
}; | ||
|
||
/** | ||
* Options | ||
*/ | ||
|
||
var options = { | ||
|
||
}; | ||
|
||
/** | ||
* Checkpoint list entry. | ||
* | ||
* @property id {Number} the sequencial identifier of a checkpoint | ||
* @property time {Number} the time when the checkpoint was created | ||
* @property sourceId {String} the source identifier | ||
* | ||
* @class | ||
* @inherits {Model} | ||
*/ | ||
|
||
var Checkpoint = module.exports = Model.extend('Checkpoint', properties, options); | ||
|
||
/** | ||
* Get the current checkpoint id | ||
* @callback {Function} callback | ||
* @param {Error} err | ||
* @param {Number} checkpointId The current checkpoint id | ||
*/ | ||
|
||
Checkpoint.current = function(cb) { | ||
this.find({ | ||
limit: 1, | ||
sort: 'id DESC' | ||
}, function(err, checkpoint) { | ||
if(err) return cb(err); | ||
cb(null, checkpoint.id); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters