diff --git a/.gitignore b/.gitignore index 4f7434ad..ff9fba59 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,6 @@ coverage/ vendor/ .bundle/ .sass-cache/ - +Guardfile pkg .DS_Store diff --git a/Changes.md b/Changes.md new file mode 100644 index 00000000..fa5cc4bf --- /dev/null +++ b/Changes.md @@ -0,0 +1,8 @@ + + +v 0.1.1 +------- + +- add Web fontend with enabled/disable job, unqueue now, delete job +- add cron poller - enqueu cro jobs +- add cron job - save all needed data to redis \ No newline at end of file diff --git a/README.rdoc b/README.rdoc index de96bc58..5486bebb 100644 --- a/README.rdoc +++ b/README.rdoc @@ -16,12 +16,115 @@ Requirements Installation ----------------- - gem install sidekiq-cron + $ gem install sidekiq-cron Getting Started ----------------- + +If you are not using Rails you need to add `require 'sidekiq-cron'` somewhere after `require 'sidekiq'`. + +_Job properties_: + +```ruby +{ + 'name' => 'name_of_job', #must be uniq! + 'cron' => '1 * * * *', + 'klass' => 'MyClass', + #OPTIONAL + 'queue' => 'name of queue', + 'args' => '[Array or Hash] of arguments hich will be passed to perform method' +} +``` + +Adding Cron job: +```ruby + +class HardWorker + include Sidekiq::Worker + def perform(name, count) + # do something + end +end + +Sidekiq::Cron::Job.create( name: 'Hard worker - every 5min', cron: '*/5 * * * *', klass: 'HardWorker') +# => true +``` + +`create` method will return only true/false if job was saved or not. + +```ruby +job = Sidekiq::Cron::Job.new( name: 'Hard worker - every 5min', cron: '*/5 * * * *', klass: 'HardWorker') + +if job.valid? + job.save +else + puts job.errors +end + +#or simple + +unless job.save + puts job.errors #will return array of errors +end +``` + +Finding jobs: +```ruby +#return array of all jobs +Sidekiq::Cron::Job.all + +#return one job by its uniq name - case sensitive +Sidekiq::Cron::Job.find "Job Name" + +#return one job by its uniq name - you can use hash with 'name' key +Sidekiq::Cron::Job.find name: "Job Name" + +#if job can't be found nil is returned +``` + +Destroy jobs: +```ruby +#destroys all jobs +Sidekiq::Cron::Job.destroy_all! + +#destroy job by its name +Sidekiq::Cron::Job.destroy "Job Name" + +#destroy founded job +Sidekiq::Cron::Job.find('Job name').destroy +``` + +Work with job: +```ruby +job = Sidekiq::Cron::Job.find('Job name') + +#disable cron scheduling +job.disable! + +#enable cron scheduling +job.enable! + +#get status of job: +job.status +# => enabled/disabled + + +#enqueue job right now! +job.enque! +``` + +How to start scheduling? +Just start sidekiq workers by: + + sidekiq + +=== Web Ui for Cron Jobs + +If you are using sidekiq web ui and you would like to add cron josb to web too, +add `require 'sidekiq-cron'` after `require 'sidekiq/web'`. +By this you will get: ![Web UI](https://github.com/ondrejbartas/sidekiq-cron/raw/master/examples/web-cron-ui.png) diff --git a/examples/web-cron-ui.png b/examples/web-cron-ui.png new file mode 100644 index 00000000..16e7fce8 Binary files /dev/null and b/examples/web-cron-ui.png differ