|
@@ -7,6 +7,7 @@ import (
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
+ "sync"
|
|
|
"text/template"
|
|
|
"time"
|
|
|
|
|
@@ -22,11 +23,10 @@ import (
|
|
|
)
|
|
|
|
|
|
type ListGenerator struct {
|
|
|
+ sync.Mutex
|
|
|
Config *config.ConfigT
|
|
|
-}
|
|
|
|
|
|
-func NewListGenerator(config *config.ConfigT) *ListGenerator {
|
|
|
- return &ListGenerator{config}
|
|
|
+ JobID uint
|
|
|
}
|
|
|
|
|
|
var funcMap template.FuncMap = template.FuncMap{
|
|
@@ -47,7 +47,7 @@ func (generator *ListGenerator) prepareRemoteFolder() {
|
|
|
func (generator *ListGenerator) generate(outputPath string, teachers []*orm.Teacher, funcMap template.FuncMap) {
|
|
|
filename := filepath.Join(outputPath, "elenco_docenti")
|
|
|
// tplContent, err := ncClient.Download("")
|
|
|
- tpl, err := tpl_util.LoadTextTemplateFromString("./generator/generators/list/list.tpl.md", funcMap)
|
|
|
+ tpl, err := tpl_util.LoadTextTemplate("./generator/generators/list/list.tpl.md", funcMap)
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
@@ -129,11 +129,21 @@ func groupClasses(classes []*orm.Class) string {
|
|
|
return strings.Join(groups, ",")
|
|
|
}
|
|
|
|
|
|
-func (generator *ListGenerator) Run(jobId uint) {
|
|
|
+func NewListGenerator(config *config.ConfigT) *ListGenerator {
|
|
|
+ return &ListGenerator{Config: config}
|
|
|
+}
|
|
|
+
|
|
|
+func (generator *ListGenerator) SetJobId(id uint) {
|
|
|
+ generator.Lock()
|
|
|
+ generator.JobID = id
|
|
|
+ generator.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+func (generator *ListGenerator) Run() {
|
|
|
ncClient, err := cloud.Dial(
|
|
|
- config.Config.Cloud.Url,
|
|
|
- config.Config.Cloud.Username,
|
|
|
- config.Config.Cloud.Password,
|
|
|
+ generator.Config.Cloud.Url,
|
|
|
+ generator.Config.Cloud.Username,
|
|
|
+ generator.Config.Cloud.Password,
|
|
|
)
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
@@ -141,15 +151,15 @@ func (generator *ListGenerator) Run(jobId uint) {
|
|
|
|
|
|
log.Printf("Connecting to karmen...")
|
|
|
client, err := karmen_client.Dial(
|
|
|
- config.Config.Url,
|
|
|
- config.Config.Admin.Username,
|
|
|
- config.Config.Admin.Password,
|
|
|
+ generator.Config.Url,
|
|
|
+ generator.Config.Admin.Username,
|
|
|
+ generator.Config.Admin.Password,
|
|
|
)
|
|
|
if err != nil {
|
|
|
log.Println(err)
|
|
|
}
|
|
|
|
|
|
- job, err := client.GetJob(jobId)
|
|
|
+ job, err := client.GetJob(generator.JobID)
|
|
|
if err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
@@ -165,7 +175,7 @@ func (generator *ListGenerator) Run(jobId uint) {
|
|
|
panic(err)
|
|
|
}
|
|
|
|
|
|
- outputPath := filepath.Join(config.Config.Documents.OutputPath, fmt.Sprintf("%d/%d", job.DocumentID, job.ID))
|
|
|
+ outputPath := filepath.Join(generator.Config.Documents.OutputPath, fmt.Sprintf("%d/%d", job.DocumentID, job.ID))
|
|
|
|
|
|
if err := os.MkdirAll(outputPath, 0777); err != nil {
|
|
|
panic(err)
|
|
@@ -177,8 +187,6 @@ func (generator *ListGenerator) Run(jobId uint) {
|
|
|
|
|
|
job.Files = append(job.Files, &orm.File{Path: "elenco_docenti.pdf"})
|
|
|
|
|
|
- time.Sleep(10 * time.Second)
|
|
|
-
|
|
|
err = client.UpdateJob(job)
|
|
|
if err != nil {
|
|
|
panic(err)
|