Project

easy_job

0.0
No commit activity in last 3 years
No release in over 3 years
Asynchronous job for Redmine, EasyRedmine and EasyProject
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 10.0
~> 3.0

Runtime

 Project Readme

EasyJob

Asynchronous job for Redmine, EasyRedmine and EasyProject.

Installation

Add this line to your application's Gemfile:

gem 'easy_job'

And then execute:

$ bundle

Or install it yourself as:

$ gem install easy_job

Usage

Delay jobs

Every methods called after .easy_delay will be delayed and executed on other thread. This method could be used for any ruby Object.

# Reschedule first issue to today
Issue.first.easy_delay.reschedule_on(Date.today)

# Save ORM object with lot of callbacks
[Issue.new, Issue.new].map { |i| i.easy_delay.save }

Mailer jobs

Deliver email later.

# Generating and sending will be done later
Mailer.issue_add(issue, ['test@example.net'], []).easy_deliver

# Email is generated now but send later
Mailer.issue_add(issue, ['test@example.net'], []).easy_safe_deliver

Custom jobs

You can also create custom task with own exceptions capturing.

Job can be started with 3 calling:

  • .perform_async(*args) started when pool cointains free worker
  • .perform_in(*args, interval:) job is added to queue after interval second
  • .perform_every(*args, interval:, timeout:, start_at:) job is executed every delay second
    • interval: seconds between task executions (required)
    • timeout: max seconds for running (optional)
    • start_at: time of first execution (optional)
class PDFJob < EasyJob::RedmineTask

  include IssuesHelper

  def perform(issue_ids, project_id)
    issues = Issue.where(id: issue_ids)
    project = Project.find(project_id)
    query = IssueQuery.new

    result = issues_to_pdf(issues, project, query)

    path = Rails.root.join('public', 'issues.pdf')
    File.open(path, 'wb') {|f| f.write(result) }
  end

end

PDFJob.perform_async(Issue.ids, Project.first.id)

Tenant

If you are using tenant you can simply use

require 'easy_job/tenant_wrapper'

Ideas for next version

  • Behaviour model.
  • Repeat after failing.
  • Dashboard.
  • Queue defining.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ondra-m/easy_job.