opencloset / volunteer

Web for opencloset volunteers
0 stars 0 forks source link

자원봉사자의 사진을 업로드 #15

Closed aanoaa closed 4 years ago

aanoaa commented 9 years ago

2015-09-09 2 10 52

keedi commented 9 years ago

본 기능은 단순히 자원 봉사자의 사진 업로드라기 보다는 사용자 사진 등록이라는 점을 고려해주시고 진행해야 할 것 같습니다. 일단은 현재 staff의 경우 gravatar 사진을 보여주고 있긴 합니다만, 뭐 아마 일반인이 gravatar 사진 등록은 거의 못할 확률이 높긴 하겠죠;;;

aanoaa commented 9 years ago

사진 뿐만 아니라 비고란도 만들어서 각 활동에 대한 코멘트를 남기고 싶어합니다.

aanoaa commented 8 years ago

user-id 별로 디렉토리 만들고 timestamp 별로 업로드한 파일의 이름을 지정하면, 따로 DB 연동할 필요없이 사용자가 업로드한 사진을 관리 할 수 있지 않을까 합니다.

profile-photos/
  234/
    1452228848.png
    1452228867.jpg
aanoaa commented 8 years ago

사용자의 프로필 사진이기 때문에 여러 프로젝트에서 공유되어야 합니다. 업로드된 사진을 이곳저곳에서 보고싶다면,

avatar.theopencloset.net

같은거 두고 gravatar 대신에 사용할 수 있으면 좋을 것 같습니다.

GET https://avatar.theopencloset.net/userid?s=50x50

이런식으로 쓸 수 있다면 좋겟네요. 프로필사진을 등록하지 않았다면 default 사진을 주고요.

aanoaa commented 8 years ago

@keedi @yongbin 저의 아이디어 어떤가여?

yongbin commented 8 years ago

user-id 별로 디렉토리 만들고 timestamp 별로 업로드한 파일의 이름을 지정하면,

저는 가능하면 BLOB을 이용해서 DB에 저장했으면 좋겠습니다. SQL 안티페턴에 '유령파일' 이라는 안티페턴으로 소개되는 건이거든요

유령 파일

    목표 : 이미지 또는 이진 데이터 저장
    안티패턴 : 이미지를 파일 시스템에 파일로 저장하고 파일에 대한 경로만 VARCHAR로 데이터베이스에 저장한다.
    해법 : 아래에 대해 모두 답할 수 있게 애플리케이션을 설계했다면 파일을 사용하고, 그렇지 못하다면 BLOB을 사용하라.
        데이터의 백업과 복원 절차에서 데이터베이스와 이미지 파일 관계를 제대로 복원할 수 있는가?
        이미지가 계속쌓이는가? 필요하지 않으면 삭제되는가? 삭제는 자동인가 수작업인가?
        이미지에 대한 권한 검사가 필요한가? 권한이 없는 이미지를 사용자가 요청하면 뭘보게 되는가?
        이미지에 대한 변경을 취소할 수 있는가? 그렇다면, 애플리케이션이 이전 상태의 이미지로 복원해야 하는가?
    Tip : 데이터베이스 밖의 리소스는 데이터베이스가 관리하지 않는다.

http://kwonnam.pe.kr/wiki/database/sqlantipatterns

aanoaa commented 8 years ago

페턴 돋음

aanoaa commented 8 years ago

@10001if 자원봉사자가 직접 사진을 업로드합니까? 아니면 staff 가 해야 하나요?

10001if commented 8 years ago

직접하게 하면 잘 안하실 것 같아서. staff가 직접 입력하려고 합니다. ^^

10001if commented 7 years ago

@aanoaa 자원봉사자가 많아졌고 담당자도 수시로 바뀌고 있습니다. 자원봉사자의 얼굴을 넣어 놓고 확인할 수 있도록 이슈 진행을 요청드립니다.

pingpongworks commented 7 years ago

자원봉사자의 사진과 함께 봉사자에 대한 코멘트를 적는 란도 꼭 필요합니다. 예를 들면, 학교, 전공, 봉사에 대한 반응 등을 옷장지기들이 그때그때 추가해서 적으려고 합니다. 매번 만나는 봉사자에게 매번 똑같은 대화를 건네는 민망함을 방지하고자 함입니다^^

aanoaa commented 7 years ago

사진을 업로드 하거나 코멘트를 작성하는 위치는 봉사활동 목록에서 이루어질 것 같습니다.

봉사활동과 관련된 작업은 staff 가 아닌 volunteer 로 분리된지 오래입니다. 해당 기능은 staff 가 아닌 volunteer 에서 진행되어야 합니다. 지금 상태로 작업이 되면 staff 에 volunteer 의 기능이 커지는 꼴 입니다.

사진/코멘트 기능 이전에 봉사활동 신청/승인/방문/취소/방문안함 목록을 staff -> volunteer 로 옮기도록 하겠습니다.

aanoaa commented 7 years ago

앞으로 봉사활동 목록은 https://volunteer.theopencloset.net/works/ 에서 관리하시면 되겠습니다,

aanoaa commented 7 years ago

목록에서 자원봉사자의 이름을 클릭해서 코멘트를 작성할 수 있습니다. 간단한 요약정보도 표시됩니다.

aanoaa commented 7 years ago

avatar.theopencloset.net 에 email 을 key 로 해서 사진을 업로드 하고 보여주도록 하면 되는데, 중요한 이슈 같지 손이 가질 않습니다.

aanoaa commented 7 years ago

avatar 서비스에 문제가 있는 듯 보입니다.

[Tue Jun 13 19:23:00 2017] [error] Can't call method "create_scaled_image" on an undefined value at lib/OpenCloset/Avatar/Web/Controller/Avatar.pm line 176.
[Tue Jun 13 19:23:03 2017] [error] Not found images: 5362
10001if commented 7 years ago

@aanoaa 당장 급한 이슈가 아닙니다. 서비스에 문제가 있다면 이슈 순위를 내리고 다른 이슈를 작업해주세요.

aanoaa commented 7 years ago

upload 는 되었는데, 썸네일을 로드하는 과정에서 실패합니다.

aanoaa commented 7 years ago

같은 파일을 업로드 했는데, test 에서와 production 에서의 image blob 크기가 다릅니다.

## localhost - test
mysql> SELECT LENGTH(image) FROM avatar_image WHERE id = 2;
+---------------+
| LENGTH(image) |
+---------------+
|         31208 |
+---------------+

## server - production
mysql> SELECT LENGTH(image) FROM avatar_image WHERE avatar_id = 5146;
+---------------+
| LENGTH(image) |
+---------------+
|         46711 |
+---------------+
aanoaa commented 7 years ago

OpenCloset-Avatar-Web 의 버전은 같습니다. 내부에서 사용하는 라이브러리의 버전 차이 혹은 mysql 의 버전 차이 일 수도 있습니다.

aanoaa commented 7 years ago

31208 크기의 파일을 업로드 했는데, 46711 image-blob 으로 들어가 있습니다.

aanoaa commented 7 years ago
$ ls --block-size=K -s aanoaa.png 
36K aanoaa.png

curl \
    -F "token=xxxxx" \
    -F "key=xxxxxxxx" \
    -F "img=@aanoaa.png" \
    https://avatar.theopencloset.net/avatar

위 스크립트로 36K 이미지 파일을 업로드 했음에도

+---------------+
| LENGTH(image) |
+---------------+
|         46711 |
+---------------+

처럼 들어갔습니다. 업로드하는 쪽이 아니라 POST request 를 받아서 처리하는 avatar 서비스의 문제로 보입니다.

aanoaa commented 7 years ago

localhost 에서의 테스트는 문제가 없는데, 어떻게 디버깅해야 하지..

aanoaa commented 7 years ago

파일을 변경해서 업로드 해보았습니다. 2487 파일을 업로드했는데, 3690 으로 들어갔습니다. 그렇다는 것은 언젠가부터 avatar 에 업로드 한 이미지가 처리되고 있는게 아닌가 싶습니다.

aanoaa commented 7 years ago

다행히도? 2017-03-10 이후로 사진을 업로드한 적이 없습니다.

aanoaa commented 7 years ago

이건 어쩔 수 없습니다. 왜 잘못된 파일이 들어가고 있는지 서버에서 테스트 하고 작업하도록 하겠습니다.

aanoaa commented 7 years ago
[Wed Jun 14 15:37:08 2017] [info] 2487

업로드한 파일은 문제가 없어 보이고 파일이 -> DB 로 들어갈때에 사이즈가 늘어납니다.

aanoaa commented 7 years ago

blob.zip source.zip

원본과 blob 데이터의 hex 파일입니다.

$ xxd source.png > source.hex
$ xxd blob.dat > blob.hex
aanoaa commented 7 years ago

응용프로그램 레벨의 문제가 아닌 것 같습니다.

aanoaa commented 7 years ago

테스트를 위해서 서버와 Mojolicious 버전을 맞추고 실행하니 아래와 같은 에러가..

Can't load application from file "/path/to/opencloset/volunteer/script/volunteer": "slurp" is not exported by the Mojo::Util module
Can't continue after import errors at /path/to/Mojo/SQLite/Migrations.pm line 6.
BEGIN failed--compilation aborted at /path/to/Mojo/SQLite/Migrations.pm line 6, <DATA> line 1.
Compilation failed in require at /path/to/Mojo/SQLite.pm line 10, <DATA> line 1.
BEGIN failed--compilation aborted at /path/to/Mojo/SQLite.pm line 10, <DATA> line 1.
Compilation failed in require at /path/to/Minion/Backend/SQLite.pm line 4, <DATA> line 1.
BEGIN failed--compilation aborted at /path/to/Minion/Backend/SQLite.pm line 4, <DATA> line 1.

Minion::Backend::SQLite, Mojolicious v7.33 과 호환성에 문제가 있는 듯 싶습니다.

aanoaa commented 7 years ago
$ cpanm Mojo::SQLite
--> Working on Mojo::SQLite
Fetching http://www.cpan.org/authors/id/D/DB/DBOOK/Mojo-SQLite-2.002.tar.gz ... OK
Configuring Mojo-SQLite-2.002 ... OK
Building and testing Mojo-SQLite-2.002 ... OK
Successfully installed Mojo-SQLite-2.002 (upgraded from 1.002)

Mojo::SQLite 버전문제 였습니다.

cpanfile 에 의존성을 적도록 하겠습니다.

aanoaa commented 7 years ago

사진을 확인 할 수 있도록 하던지 좀 더 크게 보여졌으면 좋겠다고 합니다.

10001if commented 7 years ago

확인 하였습니다. 감사합니다. ^^

10001if commented 7 years ago

@aanoaa 사진이 업로드 되지 않는다고 합니다. 더불어 의류 사진도 올라가지 않는다고 하네요. 확인 부탁드립니다.

aanoaa commented 7 years ago

확인해보니 avatar 서비스의 문제가 아니라 volunteer 에서 avatar 에 업로드하는 queue 의 문제입니다.

aanoaa commented 7 years ago
Can't exec "/path/to/volunteer.theopencloset.net/scripts/monitor": No such file or directory at /path/to/lib/perl5/Ubic/Daemon.pm line 390.

왜 volunteer 서비스인데 scripts/monitor 를 실행시키고 있는건지 모르겠습니다.

aanoaa commented 7 years ago
Jun 17 16:02 minion.stderr

opencloset.volunteer.minion 서비스를 재시작해도 로그 파일이 갱신되지 않습니다. 지난 17일 이력이 마지막입니다.

ubic 설정이 잘못된 것일까요

aanoaa commented 7 years ago

로그 파일이 만들어지는지 확인하기 위해서 opencloset.volunteer.minion -> opencloset.volunteer.worker 로 이름을 바꾸었습니다. 파일은 만들어졌지만 비어있습니다.

aanoaa commented 7 years ago

이게 문제인 것 같습니다.

[Wed Jun 28 10:12:32 2017] [fatal] Worker error: DBD::SQLite::st execute failed: database disk image is malformed at /path/to/lib/perl5/Minion/Backend/SQLite.pm line 235.
aanoaa commented 7 years ago

서버의 Minion 버전을 업그레이드 하였습니다. monitor, donation 에서도 minion 을 사용하는데 영향이 있을까 두렵습니다.

$ cpanm Minion
--> Working on Minion
Fetching http://www.cpan.org/authors/id/S/SR/SRI/Minion-7.01.tar.gz ... OK
Configuring Minion-7.01 ... OK
Building and testing Minion-7.01 ... OK
Successfully installed Minion-7.01 (upgraded from 6.05)
aanoaa commented 7 years ago
$ cpanm Minion::Backend::SQLite
--> Working on Minion::Backend::SQLite
Fetching http://www.cpan.org/authors/id/D/DB/DBOOK/Minion-Backend-SQLite-2.000.tar.gz ... OK
Configuring Minion-Backend-SQLite-2.000 ... OK
Building and testing Minion-Backend-SQLite-2.000 ... OK
Successfully installed Minion-Backend-SQLite-2.000 (upgraded from 0.007)
1 distribution installed

서버의 Minion::Backend::SQLite 모듈을 업그레이드 하였습니다.

aanoaa commented 7 years ago

사진 업로드 후에 avatar 에 사진을 업로드 하기 위한 enqueue 가 되지 않는 것 같습니다. 자세한 것은 로그를 찍어봐야 하겠습니다.

aanoaa commented 7 years ago

서버에서의 결과입니다.

$ sqlite3 minion.db 
sqlite> .tables
# empty

제 local 에서의 결과 입니다.

$ sqlite3 minion.db 
sqlite> .tables
minion_jobs      minion_workers   mojo_migrations

서버의 minion DB 에 테이블이 없습니다.

aanoaa commented 7 years ago

minion.db 파일을 삭제하고 application 을 재시작하면 minion.db 파일이 만들어져야 합니다. 제 local test 환경에서는 문제가 없는데, 서버에서는 만들어 지기는 하지만 table 이 비어있습니다.

이 문제부터 해결해야 하겠습니다.

aanoaa commented 7 years ago

환경변수나 path 등의 문제인 것 같은데 도움이 필요합니다.

$ cd /path/to/volunteer.theopencloset.net/
$ ubic stop opencloset.volunteer
$ rm minion.db
$ ubic stop opencloset.volunteer
$ sqlite3 minion.db
sqlite> .tables

했을때에 아래의 결과가 나오면 됩니다.

minion_jobs      minion_locks     minion_workers   mojo_migrations

cc @keedi @yongbin

aanoaa commented 7 years ago

테스트를 위해서라면 volunteer 서비스는 내려가도 괜찮습니다.

yongbin commented 7 years ago

서버에서 생성된 minion sqlite db 파일을 제 로컬에 내려받은뒤 확인해보면 테이블 목록이 잘 나오고 있습니다.

제 로컬의 sqlite 버전

3.16.0 2016-11-04 19:09:39 0e5ffd9123d6d2d2b8f3701e8a73cc98a3a7ff5f

서버의 sqlite 버전

3.7.13 2012-06-11 02:05:22 f5b5a13f7394dc143aa136f1d4faba6839eaa6dc
yongbin commented 7 years ago

http://search.cpan.org/~ishigaki/DBD-SQLite-1.54/lib/DBD/SQLite.pm

SQLITE VERSION ^

DBD::SQLite is usually compiled with a bundled SQLite library (SQLite version
3.13.0 as of this release) for consistency. However, a different version of
SQLite may sometimes be used for some reasons like security, or some new
experimental features.

You can look at $DBD::SQLite::sqlite_version (3.x.y format) or
$DBD::SQLite::sqlite_version_number (3xxxyyy format) to find which version of
SQLite is actually used. You can also check
DBD::SQLite::Constants::SQLITE_VERSION_NUMBER().

현재 서버에서 생성된 db 파일은 sqlite3 3.13.0 버전인것으로 보입니다. opencloset 계정에서 다음 명령으로 확인가능합니다.

perl -MDBD::SQLite -E 'say $DBD::SQLite::sqlite_version'
3.13.0

따라서 두가지 문제로 나눠지는거 같습니다.

  1. DBD::SQLite 가 생성한 3.13.0 버전의 sqlite3 db 파일을 3.7.13 버전의 서버 클라이언트가 처리못하는 문제
  2. 동일한 3.13.0 버전으로 생성된 db를 DBD::SQLite 가 잘 처리하지 못하는 문제

장애와 직접적인 관련이 있다고 의심받는 문제는 2번입니다.

yongbin commented 7 years ago

우선 2를 확인하기 위해서 다음과 같은 코드를 실행했습니다.

use strict;
use warnings;
use v5.18;

use Data::Dumper;
use Mojo::SQLite;

# Select the library version
my $sql = Mojo::SQLite->new('sqlite:test.db');
say $sql->db->query('select sqlite_version() as version')->hash->{version};

# Use migrations to create a table
$sql->migrations->name('my_names_app')->from_string(<<EOF)->migrate;
-- 1 up
create table names (id integer primary key autoincrement, name text);
-- 1 down
drop table names;
EOF

# Use migrations to drop and recreate the table
$sql->migrations->migrate(0)->migrate;

# Get a database handle from the cache for multiple queries
my $db = $sql->db;

# Use SQL::Abstract to generate simple CRUD queries for you
$db->insert('names', {name => 'Isabel'});
my $id = $db->select('names', ['id'], {name => 'Isabel'})->hash->{id};
$db->update('names', {name => 'Bel'}, {id => $id});
#$db->delete('names', {name => 'Bel'});

say Dumper $sql->db->query('select * from names ')->hash;

결과

3.13.0
$VAR1 = {
          'id' => 1,
          'name' => 'Bel'
        };

우선 DBD::SQLite 로 생성된 3.13.0 db를 대상으로 한 간단한 create / insert / update / select 는 동작하는것으로 보입니다. 따라서 장애가 나는건 SQLite 와 다른 이슈일 가능성이 있습니다.

yongbin commented 7 years ago

DBD::SQLite 가 생성한 3.13.0 버전의 sqlite3 db 파일을 3.7.13 버전의 서버 클라이언트가 처리못하는 문제

이건 우선순위가 낮기때문에 우선 원활하게 디버깅을 하기위해서 서버에 sqlite 3.19.3 버전을 컴파일 완료했습니다.

현재 서버에서 다음과 같은 명령으로 DB 상태를 바로 확인할 수 있습니다.

~/tmp/sqlite/sqlite3 minion.db

현재 DB내용은 다음과 같습니다.

SQLite version 3.19.3 2017-06-08 14:26:16
Enter ".help" for usage hints.
sqlite> .tables
minion_jobs      minion_locks     minion_workers   mojo_migrations
sqlite> select * from minion_jobs;
1|[23,"bar"]|2017-06-28 07:19:12|2017-06-28 07:19:12||0|||0||inactive|foo||default|1|[]|{}
sqlite> select * from minion_workers;
1|opencloset1.silex.kr|22755|2017-06-28 07:20:30|2017-06-28 07:45:31|[]|{"command_interval":10,"heartbeat_interval":300,"jobs":4,"performed":0,"queues":["default"],"repair_interval":18415}
sqlite>

queue에 있는 내용은 제가 테스트를 위해서 CLI에서 다음명령을 통해서 enqueue 한 내용입니다.

MOJO_CONFIG='volunteer.conf' ./script/volunteer minion job -e foo -a '[23, "bar"]'

이제 웹에서 큐에 넣는 작업을 진행하고 큐에 잘 쌓이는지 여부를 확인해야합니다.