Skip to content

Commit

Permalink
Merged in shivam/embedded-update-job-interval-reduction (pull request #9
Browse files Browse the repository at this point in the history
)

Shivam/embedded update job interval reduction
  • Loading branch information
Shivam Pandey authored and Hardik Modha committed Feb 27, 2018
2 parents ab0eabb + 6c963c2 commit 1677855
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 8 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Mongo Update Embedded Plugin for Grails 3.1.x

Latest Version (0.0.7)
Latest Version (0.0.9)

### Installation

Expand Down Expand Up @@ -34,6 +34,17 @@ You will have to create a class that will represent embedded objects of the pare

This class needs to implement the trait `EmbeddableDomain` which contains some necessary methods to treat a class as an embeddable class.

** Override the UpdateEmbeddedInstancesJob schedule **
By default it is set to update at every 2 minutes but if you want to override the schedule, Add the following block in the `application.groovy` of installing app.

```
// Override startDelay and repeatInterval of UpdateEmbeddedInstancesJob
jobs {
mongo.update.embedded.startDelay = 120000 // 120 Seconds
mongo.update.embedded.repeatInterval = 30000 // 30 seconds
}
```

**Example:** For a domain class `User` you can create an embedded class called `EmUser` under `src/main/groovy`.

```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
}
}

version "0.0.8"
version "0.0.9"
group "com.causecode.plugins"

apply plugin:"eclipse"
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.0.9] - [Unreleased]

### Added
- Functionality to externalize the scheduling of UpdateEmbeddedInstancesJob.

## [0.0.8] - 2017-10-27

###Fixed
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Nov 03 18:21:22 IST 2017
#Thu Feb 22 10:47:18 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip
5 changes: 5 additions & 0 deletions grails-app/domain/test/TestDomainA.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ class TestDomainA {

Status status = Status.ONE

Date dateCreated
Date lastUpdated

EmTestDomainA getEmbeddedInstance() {
return new EmTestDomainA(this.id, this.testField1, this.status)
}

static embedded = ['embeddingNonDomainField']

static constraints = {
dateCreated bindable: false
lastUpdated bindable: false
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions grails-app/domain/test/TestDomainB.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ class TestDomainB {
EmTestDomainA testDomainA
Set<EmTestDomainA> testDomainASet

Date dateCreated
Date lastUpdated

static embedded = ['testDomainA', 'testDomainASet']

static constraints = {
dateCreated bindable: false
lastUpdated bindable: false
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions grails-app/domain/test/TestDomainC.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@ class TestDomainC {

Map<String, String> mapOfString = [:]

Date dateCreated
Date lastUpdated

static embedded = ['collectionTypeListOfObjects']

static constraints = {
dateCreated bindable: false
lastUpdated bindable: false
}

EmTestDomainC getEmbeddedInstance() {
return new EmTestDomainC([
instanceId: this.id,
Expand Down
6 changes: 5 additions & 1 deletion grails-app/domain/test/TestDomainD.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ class TestDomainD {

EmTestDomainC emTestDomainC

Date dateCreated
Date lastUpdated

static embedded = ['emTestDomainC']

static constraints = {

dateCreated bindable: false
lastUpdated bindable: false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
*/
package com.causecode.mongo

import grails.util.Holders

/**
* This Job is used for processing the pending embedded instances queue. This job starts with a delay of 2 minutes
* and repeats every 2 minutes.
* This Job is used for processing the pending embedded instances queue. This job starts with overridden startDelay and
* repeatInterval provided by installing app otherwise with a default delay of 2 minutes and repeats every 2 minutes.
*
* @author Nikhil Sharma
* @since 0.0.1
Expand All @@ -21,7 +23,8 @@ class UpdateEmbeddedInstancesJob {
static final long TWO_MINUTES = 120000

static triggers = {
simple startDelay: TWO_MINUTES, repeatInterval: TWO_MINUTES
simple startDelay: Holders.config.jobs.mongo.update.embedded.startDelay ?: TWO_MINUTES,
repeatInterval: Holders.config.jobs.mongo.update.embedded.repeatInterval ?: TWO_MINUTES
}

def execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ trait EmbeddableDomain implements Validateable {
return !field.type.isInterface()
}
}

// Collect as map from non synthetic & non static fields
.collectEntries { Field field ->
def fieldValue = instance[field.name]
Expand Down

0 comments on commit 1677855

Please sign in to comment.