Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GO Email Worker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pasan Mallawaarachchi
GO Email Worker
Commits
ad8bc85d
Commit
ad8bc85d
authored
Apr 12, 2019
by
Pasan Mallawaarachchi
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go worker with attachments
parent
5b1b6c78
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
39 deletions
+44
-39
config.yaml
config.yaml
+2
-2
worker.go
worker.go
+42
-37
No files found.
config.yaml
View file @
ad8bc85d
...
@@ -19,8 +19,8 @@ requests:
...
@@ -19,8 +19,8 @@ requests:
header_type
:
Content-Type
header_type
:
Content-Type
header_json
:
application/json
header_json
:
application/json
mailgun
:
mailgun
:
domain
:
sandbox69b93297d9f045b5ae2383ee3b5d234c.mailgun.org
domain
:
mailgun-bp.comsolvia.se
apikey
:
0b6326227e0797740c93e5cfffc901c1-49a2671e-e9e05eca
apikey
:
68efe0d516a7f70133fee60a2cd5ceba-6140bac2-41d4c8d2
error_report
:
error_report
:
error_sender
:
qa@parkwaylabs.com
error_sender
:
qa@parkwaylabs.com
error_head
:
Email Worker Crashed
error_head
:
Email Worker Crashed
...
...
worker.go
View file @
ad8bc85d
...
@@ -10,14 +10,14 @@ package main
...
@@ -10,14 +10,14 @@ package main
*/
*/
import
(
import
(
"context"
"context"
"encoding/base64"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io"
"io/ioutil"
"io/ioutil"
"log"
"log"
"net/http"
"net/http"
"os"
"os"
"
path
"
"
strconv
"
"strings"
"strings"
"sync"
"sync"
"time"
"time"
...
@@ -106,7 +106,7 @@ var waitGroup sync.WaitGroup
...
@@ -106,7 +106,7 @@ var waitGroup sync.WaitGroup
var
mailData
chan
string
var
mailData
chan
string
var
outboxReadTime
chan
string
var
outboxReadTime
chan
string
var
outboxDeleteTime
chan
string
var
outboxDeleteTime
chan
string
var
file
N
ame
=
""
var
file
n
ame
=
""
func
main
()
{
func
main
()
{
// get configurations
// get configurations
...
@@ -122,7 +122,8 @@ func main() {
...
@@ -122,7 +122,8 @@ func main() {
_
,
reqErrOutbox
:=
http
.
NewRequest
(
config
.
Requests
.
Get
,
config
.
Curl
.
CheckMail
,
nil
)
_
,
reqErrOutbox
:=
http
.
NewRequest
(
config
.
Requests
.
Get
,
config
.
Curl
.
CheckMail
,
nil
)
if
reqErrOutbox
!=
nil
{
if
reqErrOutbox
!=
nil
{
fmt
.
Println
(
"Error Connectiong to CouchDB"
)
fmt
.
Println
(
"Error Connectiong to CouchDB. Error is :
\n
"
+
reqErrOutbox
.
Error
())
// panic(reqErrOutbox)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
else
{
}
else
{
...
@@ -342,11 +343,41 @@ func worker(i int) {
...
@@ -342,11 +343,41 @@ func worker(i int) {
}
}
if
len
(
attachment
)
>
0
{
if
len
(
attachment
)
>
0
{
//url := "http://www.orimi.com/pdf-test.pdf"
//url := "http://www.orimi.com/pdf-test.pdf"
r
,
_
:=
http
.
NewRequest
(
"GET"
,
attachment
,
nil
)
attachReq
,
_
:=
http
.
NewRequest
(
"GET"
,
attachment
,
nil
)
fileName
=
path
.
Base
(
r
.
URL
.
Path
)
attchResp
,
err
:=
http
.
DefaultClient
.
Do
(
attachReq
)
getFile
(
fileName
,
attachment
)
// if
message
.
AddHeader
(
"Content-Type"
,
"multipart/form-data"
)
//if(attachErr != nil)
message
.
AddAttachment
(
fileName
)
//attchResp, err := http.DefaultClient.Do(attachReq)
if
err
!=
nil
{
panic
(
err
)
}
defer
attchResp
.
Body
.
Close
()
respbody
,
_
:=
ioutil
.
ReadAll
(
attchResp
.
Body
)
resp
:=
string
(
respbody
)
time
:=
time
.
Now
()
.
UnixNano
()
filename
=
strconv
.
FormatInt
(
time
,
10
)
+
".pdf"
dec
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
resp
)
if
err
!=
nil
{
panic
(
err
)
}
f
,
err
:=
os
.
Create
(
filename
)
if
err
!=
nil
{
panic
(
err
)
}
//defer f.Close()
if
_
,
err
:=
f
.
Write
(
dec
);
err
!=
nil
{
panic
(
err
)
}
if
err
:=
f
.
Sync
();
err
!=
nil
{
panic
(
err
)
}
//message.AddHeader("Content-Type", "multipart/form-data")
message
.
AddAttachment
(
filename
)
// message.AddReaderAttachment(filename, f)
}
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
30
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
30
)
...
@@ -356,8 +387,8 @@ func worker(i int) {
...
@@ -356,8 +387,8 @@ func worker(i int) {
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
//alertAdmin(" MAilgun Error \n" + err.Error())
//alertAdmin(" MAilgun Error \n" + err.Error())
}
}
if
len
(
attachment
)
>
0
{
if
len
(
filename
)
>
0
{
os
.
Remove
(
file
N
ame
)
os
.
Remove
(
file
n
ame
)
}
}
//fmt.Println(resp)
//fmt.Println(resp)
if
config
.
AppMod
.
Production
==
"0"
{
if
config
.
AppMod
.
Production
==
"0"
{
...
@@ -452,32 +483,6 @@ func alertAdmin(err string) {
...
@@ -452,32 +483,6 @@ func alertAdmin(err string) {
}
}
/**
* Gets the file from given URL
*/
func
getFile
(
fileName
,
url
string
)
{
// Get the data
resp
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
panic
(
err
)
}
defer
resp
.
Body
.
Close
()
// Create the file
out
,
err
:=
os
.
Create
(
fileName
)
if
err
!=
nil
{
panic
(
err
)
}
defer
out
.
Close
()
// Write the body to file
_
,
err
=
io
.
Copy
(
out
,
resp
.
Body
)
if
err
!=
nil
{
panic
(
err
)
}
}
/**
/**
* log worker tasks
* log worker tasks
*/
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment