Skip to content

Commit 76cdb68

Browse files
authored
feat: media matching (#18)
- add blake2b and conversation aggregates; - add some unit tests - add genserver for rabbitmq - add sentry for exception reporting
1 parent 416e71d commit 76cdb68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2258
-190
lines changed

.formatter.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
import_deps: [:ecto, :ecto_sql, :phoenix],
33
subdirectories: ["priv/*/migrations"],
44
plugins: [Phoenix.LiveView.HTMLFormatter],
5-
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
5+
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/*.exs"]
66
]

.iex.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ import Ecto.Query
55
alias DAU.Feed
66
alias DAU.Feed.Common
77
alias DAU.UserMessage.Inbox
8+
9+
alias DAU.MediaMatch.{
10+
Hash,
11+
HashMeta,
12+
HashWorkerGenServer,
13+
HashWorkerRequest,
14+
HashWorkerResponse
15+
}

config/config.exs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import Config
1010
config :dau,
1111
namespace: DAU,
1212
ecto_repos: [DAU.Repo],
13-
generators: [timestamp_type: :utc_datetime]
13+
generators: [timestamp_type: :utc_datetime],
14+
env: config_env()
1415

1516
# Configures the endpoint
1617
config :dau, DAUWeb.Endpoint,
@@ -62,6 +63,15 @@ config :logger, :console,
6263
# Use Jason for JSON parsing in Phoenix
6364
config :phoenix, :json_library, Jason
6465

66+
config :sentry,
67+
dsn:
68+
"https://38b2487d72b7a30d5bf6ca606dfd5c25@o4507162180976640.ingest.de.sentry.io/4507163464237136",
69+
environment_name: Mix.env(),
70+
enable_source_code_context: true,
71+
root_source_code_paths: [File.cwd!()]
72+
73+
config :dau, AWSS3, file_prefix: "temp"
74+
6575
# Import environment specific config. This must remain at the bottom
6676
# of this file so it overrides the configuration defined above.
6777
import_config "#{config_env()}.exs"

config/dev.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ config :ex_aws,
8585
secret_access_key: {:system, "AWS_SECRET_ACCESS_KEY"},
8686
region: "ap-south-1"
8787

88-
config :dau, RabbitMQ, url: "amqp://admin:Admin123@localhost"
88+
config :dau, AWSS3, file_prefix: "app-data"

config/prod.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ config :logger, level: :info
1818

1919
# Runtime production configuration, including reading
2020
# of environment variables, is done on config/runtime.exs.
21+
22+
config :dau, AWSS3, file_prefix: "app-data"

config/runtime.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ config :ex_aws,
8383
access_key_id: {:system, "AWS_ACCESS_KEY_ID"},
8484
secret_access_key: {:system, "AWS_SECRET_ACCESS_KEY"}
8585

86+
rabbit_mq_url =
87+
System.get_env("RABBITMQ_URL") ||
88+
raise """
89+
Slack webhook url is missing. Please contact tattle admin
90+
"""
91+
92+
config :dau, RabbitMQ, url: rabbit_mq_url
93+
8694
if config_env() == :prod do
8795
# database_url =
8896
# System.get_env("DATABASE_URL") ||

config/test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ config :logger, level: :warning
3434

3535
# Initialize plugs at runtime for faster test compilation
3636
config :phoenix, :plug_init_mode, :runtime
37+
38+
config :dau, RabbitMQ, url: "amqp://admin:Admin123@localhost"

docker-compose.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,44 @@ services:
2121
restart: always
2222
ports:
2323
- 8080:8080
24+
25+
queue:
26+
image: rabbitmq@sha256:e2505f78d58dca8c372cde3930e4d6bee5e02ac9001ce85ece5a11df606c1fa3 # rabbitmq:3.12.12-management
27+
container_name: rabbitmq
28+
hostname: rabbitmq
29+
volumes:
30+
- ./.docker/rabbitmq/data:/var/lib/rabbitmq
31+
- ./.docker/rabbitmq/logs:/var/log/rabbitmq
32+
environment:
33+
RABBITMQ_ERLANG_COOKIE: "secret-cookie"
34+
RABBITMQ_DEFAULT_USER: "admin"
35+
RABBITMQ_DEFAULT_PASS: "Admin123"
36+
ports:
37+
- 5672:5672
38+
- 15672:15672
39+
healthcheck:
40+
test: ["CMD", "curl", "-f", "http://localhost:15672"]
41+
interval: 30s
42+
timeout: 10s
43+
retries: 5
44+
45+
hash_worker:
46+
image: tattletech/feluda-operator-hash:worker-amd64-latest
47+
container_name: hash_worker
48+
depends_on:
49+
- queue
50+
environment:
51+
MQ_USERNAME: admin
52+
MQ_PASSWORD: Admin123
53+
MQ_HOST: rabbitmq
54+
AWS_ACCESS_KEY_ID: AKIAZEOQEMFTJS244746
55+
AWS_SECRET_ACCESS_KEY: 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
56+
AWS_BUCKET: staging.dau.tattle.co.in
57+
AWS_REGION: ap-south-1
58+
command:
59+
- /bin/sh
60+
- -c
61+
- |
62+
echo "sleep for 10sec"
63+
sleep 10
64+
python -m worker.hash.hash_worker

lib/aws_s3.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
defmodule AWSS3 do
2+
require Logger
23
alias ExAws.S3
34

45
@opts [query_params: [{"x-amz-acl", "public-read"}]]
6+
@file_prefix Application.compile_env(:dau, [AWSS3, :file_prefix])
57

68
@doc """
79
Get a short lived URL to file on S3
@@ -28,7 +30,7 @@ defmodule AWSS3 do
2830
def upload_to_s3(url) do
2931
{:ok, _, _headers, ref} = :hackney.get(url)
3032
{:ok, body} = :hackney.body(ref)
31-
file_key = "app-data/#{UUID.uuid4()}"
33+
file_key = "#{@file_prefix}/#{UUID.uuid4()}"
3234
file_hash = :crypto.hash(:sha256, body) |> Base.encode16() |> String.downcase()
3335
S3.put_object("staging.dau.tattle.co.in", file_key, body) |> ExAws.request!()
3436
{file_key, file_hash}

lib/dau/application.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ defmodule DAU.Application do
77

88
@impl true
99
def start(_type, _args) do
10+
:logger.add_handler(:my_sentry_handler, Sentry.LoggerHandler, %{
11+
config: %{metadata: [:file, :line]}
12+
})
13+
1014
children = [
1115
DAUWeb.Telemetry,
1216
DAU.Repo,
1317
{DNSCluster, query: Application.get_env(:dau, :dns_cluster_query) || :ignore},
1418
{Phoenix.PubSub, name: DAU.PubSub},
1519
# Start the Finch HTTP client for sending emails
1620
{Finch, name: DAU.Finch},
21+
DAU.MediaMatch.HashWorkerGenServer,
1722
# Start a worker by calling: DAU.Worker.start_link(arg)
1823
# {DAU.Worker, arg},
1924
# Start to serve requests, typically the last entry

0 commit comments

Comments
 (0)