This repository has been archived by the owner on Sep 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* moves capi recipe indexing logic to common * update test imports * adds indexer sbt project * slightly more helpful error message * Remove RecipeStatusPendingCuration from list of curatedStatuses
- Loading branch information
Emma Milner
authored
Jan 24, 2017
1 parent
37a92fa
commit 706e578
Showing
18 changed files
with
143 additions
and
26 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
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
2 changes: 1 addition & 1 deletion
2
...gu/recipeasy/services/AtomPublisher.scala → ...gu/recipeasy/services/AtomPublisher.scala
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../recipeasy/services/PublisherConfig.scala → .../recipeasy/services/PublisherConfig.scala
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
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
2 changes: 1 addition & 1 deletion
2
...om/gu/recipeasy/services/Teleporter.scala → ...om/gu/recipeasy/services/Teleporter.scala
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
2 changes: 1 addition & 1 deletion
2
...recipeasy/services/ThriftSerializer.scala → ...recipeasy/services/ThriftSerializer.scala
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
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,2 @@ | ||
data/ | ||
application.conf |
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,16 @@ | ||
aws { | ||
atom.auxiliary.stsRoleArn="" | ||
atom.content.stsRoleArn="" | ||
} | ||
|
||
capi.key="" | ||
|
||
db { | ||
ctx.dataSourceClassName=org.postgresql.ds.PGSimpleDataSource | ||
ctx.dataSource.user=recipeasy | ||
ctx.dataSource.password="" | ||
ctx.dataSource.databaseName=recipeasy | ||
ctx.dataSource.portNumber=7777 | ||
ctx.dataSource.serverName=localhost | ||
ctx.connectionTimeout=30000 | ||
} |
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
<logger name="com.ning.http.client" level="WARN"/> | ||
</configuration> |
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,53 @@ | ||
package indexer | ||
|
||
import akka.actor.ActorSystem | ||
import akka.stream.ActorMaterializer | ||
import com.amazonaws.regions.{ Region, Regions } | ||
import com.amazonaws.services.kinesis.model.PutRecordResult | ||
import com.gu.contentapi.client.GuardianContentClient | ||
import com.gu.recipeasy.db.{ ContextWrapper, DB } | ||
import com.gu.recipeasy.services._ | ||
import com.typesafe.config.ConfigFactory | ||
import play.api.Configuration | ||
import play.api.libs.ws.ahc.AhcWSClient | ||
|
||
import scala.concurrent.Future | ||
import scala.util.{ Failure, Success, Try } | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
object Indexer extends App { | ||
|
||
if (args.isEmpty) { | ||
Console.err.println("Usage: Indexer <STAGE>") | ||
sys.exit(1) | ||
} | ||
|
||
val stage = args(0) | ||
val contextWrapper = new ContextWrapper { val config = ConfigFactory.load() } | ||
val config = new Configuration(ConfigFactory.load()) | ||
val db = new DB(contextWrapper) | ||
|
||
implicit val actorSystem = ActorSystem() | ||
implicit val materializer = ActorMaterializer() | ||
val teleporter = new Teleporter(AhcWSClient()) | ||
val region = Region.getRegion(Regions.fromName(Regions.EU_WEST_1.getName)) | ||
|
||
val publisherConfig = PublisherConfig(config, region, stage) | ||
|
||
val contentApiClient = new ContentApi(contentApiClient = new GuardianContentClient(publisherConfig.contentAtomConfig.capiKey)) | ||
|
||
val curatedRecipeIds: List[String] = db.getCuratedRecipesIds() | ||
|
||
curatedRecipeIds.foreach { r => | ||
val fresult: Future[Try[List[PutRecordResult]]] = RecipePublisher.publishRecipe(r, db, publisherConfig, teleporter, contentApiClient) | ||
fresult.map { result => | ||
result match { | ||
case Success(_) => println(s"Successfully published $r") | ||
case Failure(error) => println(s"Failed to published $r") | ||
} | ||
} | ||
|
||
Thread.sleep(1000) | ||
} | ||
|
||
} |
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,30 @@ | ||
#!/bin/bash | ||
# | ||
# Connects localhost to PROD database and reindexes | ||
# Requires application.conf to be correctly populated | ||
|
||
aws rds describe-db-instances 1>/dev/null | ||
if [ "$?" -eq 255 ] | ||
then | ||
echo You need to have valid capi and composer AWS credentials | ||
exit | ||
else | ||
rds_host=$(aws rds describe-db-instances --db-instance-identifier recipeasy-rds-primary-prod | jq -r .DBInstances[].Endpoint.Address 2>/dev/null) | ||
ec2=$(marauder -s stage=PROD stack=content-api-recipeasy app=recipeasy 2>/dev/null) | ||
stage=${1?Stage missing, use CODE or PROD} | ||
|
||
echo Setting up SSH tunnel | ||
ssh -o StrictHostKeyChecking=no -N -L 7777:${rds_host}:5432 ubuntu@${ec2} & | ||
SSH_PID=$! | ||
|
||
trap finish SIGINT EXIT | ||
function finish { | ||
kill $SSH_PID | ||
} | ||
|
||
sleep 3 | ||
|
||
echo Running reindex | ||
|
||
sbt "indexer/run $stage" | ||
fi |
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
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
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
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
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