當前位置: 首頁>>代碼示例>>Golang>>正文


Golang job.Job類代碼示例

本文整理匯總了Golang中github.com/darkhelmet/tinderizer/job.Job的典型用法代碼示例。如果您正苦於以下問題:Golang Job類的具體用法?Golang Job怎麽用?Golang Job使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Job類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Process

func (e *Extractor) Process(job J.Job) {
	job.Progress("Extracting...")

	defer e.wg.Done()
	resp, err := e.extractRetry(job.Url, job.Content)
	if err != nil {
		e.error(job, "%s", err)
		return
	}

	doc, err := rewriteAndDownloadImages(job.Root(), resp.Content)
	if err != nil {
		e.error(job, "HTML parsing failed: %s", err)
		return
	}

	job.Doc = doc
	if resp.Title != "" {
		job.Title = resp.Title
	}
	job.Domain = resp.Domain
	if resp.Author != nil {
		job.Author = *resp.Author
	}

	job.Progress("Extraction complete...")
	e.Output <- job
}
開發者ID:yindeming,項目名稱:ForrestFire,代碼行數:28,代碼來源:extractor.go

示例2: Process

func (c *Cleaner) Process(job J.Job) {
	defer c.wg.Done()
	if job.Friendly != "" {
		job.Progress(job.Friendly)
	}

	os.RemoveAll(job.Root())
}
開發者ID:darkhelmet,項目名稱:ForrestFire,代碼行數:8,代碼來源:cleaner.go

示例3: writeHTML

func writeHTML(job J.Job) error {
	file, err := os.OpenFile(job.HTMLFilePath(), os.O_CREATE|os.O_WRONLY, 0644)
	if err != nil {
		return fmt.Errorf("failed opening file: %s", err)
	}
	defer file.Close()

	if err = template.Execute(file, &job); err != nil {
		return fmt.Errorf("failed executing template: %s", err)
	}
	return nil
}
開發者ID:darkhelmet,項目名稱:ForrestFire,代碼行數:12,代碼來源:kindlegen.go

示例4: Process

func (e *Emailer) Process(job J.Job) {
	job.Progress("Sending to your Kindle...")

	defer e.wg.Done()
	if st, err := os.Stat(job.MobiFilePath()); err != nil {
		e.error(job, FriendlyMessage, "Something weird happened. Mobi is missing: %s", err)
		return
	} else {
		if st.Size() > MaxAttachmentSize {
			blacklist.Blacklist(job.Url)
			e.error(job, "Sorry, this article is too big to send!", "Attachment was too big (%d bytes)", st.Size())
			return
		}
	}

	m := &postmark.Message{
		From:     e.from,
		To:       job.Email,
		Subject:  Subject,
		TextBody: fmt.Sprintf("Straight to your Kindle! %s: %s", job.Title, job.Url),
	}

	if err := m.Attach(job.MobiFilePath()); err != nil {
		e.error(job, FriendlyMessage, "failed attaching file: %s", err)
		return
	}

	resp, err := e.postmark.Send(m)
	if resp == nil {
		e.error(job, FriendlyMessage, "failed sending email: %s", err)
		return
	}

	switch resp.ErrorCode {
	case 0:
		// All is well
	case 422:
		e.error(job, FriendlyMessage, "failed sending email: %s: %s", err, resp.Message)
		return
	case 300:
		e.error(job, "Your email appears invalid. Please try carefully remaking the bookmarklet.", "emailer: Email inactive or invalid")
		return
	case 406:
		e.error(job, "Your email appears to have bounced. Amazon likes to bounce emails sometimes, and my provider 'deactivates' the email. For now, try changing your Personal Documents Email. I'm trying to find a proper solution for this :(", "emailer: Email inactive or invalid")
		return
	default:
		e.error(job, FriendlyMessage, "Something bizarre happened with Postmark: %s", resp.Message)
		return
	}

	job.Progress("All done! Grab your Kindle and hang tight!")
	cache.Set(resp.MessageID, job.Url, OneHour)
	recordDurationStat(job)
	e.Output <- job
}
開發者ID:darkhelmet,項目名稱:ForrestFire,代碼行數:55,代碼來源:emailer.go

示例5: Process

func (k *Kindlegen) Process(job J.Job) {
	job.Progress("Optimizing for Kindle...")

	defer k.wg.Done()
	if err := writeHTML(job); err != nil {
		k.error(job, err.Error())
		return
	}

	cmd := exec.Command(k.binary, []string{job.HTMLFilename()}...)
	cmd.Dir = job.Root()
	out, err := cmd.CombinedOutput()
	if !fileExists(job.MobiFilePath()) {
		k.error(job, "failed running kindlegen: %s {output=%s}", err, out)
		return
	}

	job.Progress("Optimization complete...")
	k.Output <- job
}
開發者ID:darkhelmet,項目名稱:ForrestFire,代碼行數:20,代碼來源:kindlegen.go

示例6: error

func (e *Emailer) error(job J.Job, friendly, format string, args ...interface{}) {
	logger.Printf(format, args...)
	job.Friendly = friendly
	e.Error <- job
}
開發者ID:darkhelmet,項目名稱:ForrestFire,代碼行數:5,代碼來源:emailer.go

示例7: error

func (e *Extractor) error(job J.Job, format string, args ...interface{}) {
	logger.Printf(format, args...)
	job.Friendly = FriendlyMessage
	e.Error <- job
}
開發者ID:yindeming,項目名稱:ForrestFire,代碼行數:5,代碼來源:extractor.go

示例8: error

func (k *Kindlegen) error(job J.Job, format string, args ...interface{}) {
	logger.Printf(format, args...)
	job.Friendly = FriendlyMessage
	k.Error <- job
}
開發者ID:darkhelmet,項目名稱:ForrestFire,代碼行數:5,代碼來源:kindlegen.go


注:本文中的github.com/darkhelmet/tinderizer/job.Job類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。