Skip to content

Commit

Permalink
Merge pull request #1769 from ontohub/1476-re_anaylse_old_ontologies
Browse files Browse the repository at this point in the history
1476 re-anaylse old ontologies
  • Loading branch information
ebolloff committed Aug 10, 2016
2 parents 22f8827 + 628995a commit e45a347
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/repository/git.rb
Expand Up @@ -66,9 +66,9 @@ def save_file_only(tmp_file, filepath, message, user)

def commit_for!(commit_oid, pusher)
instance = Commit.where(repository_id: self,
commit_oid: commit_oid,
pusher_id: pusher.try(:id),
pusher_name: pusher.try(:name)).first_or_initialize
commit_oid: commit_oid).
first_or_initialize(pusher_id: pusher.try(:id),
pusher_name: pusher.try(:name))
instance.fill_commit_instance! unless instance.persisted?
instance
end
Expand Down
37 changes: 37 additions & 0 deletions doc/sidekiq_tips.md
@@ -0,0 +1,37 @@
# Sidekiq Tips

## Add job to queue other than specified in the Worker class
You can add a job to a queue different from the one that is specified in the worker class.
Instead of

```ruby
SomeWorker.perform_async(some, arguments)
```

you can execute

```ruby
Sidekiq::Client.push('queue' => 'some_other_queue',
'class' => SomeWorker,
'args' => [some, arguments])
```
This method accepts the following keys:
* `queue` - the named queue to use, default `'default'`
* `class` - the worker class to call, required
* `args` - an array of simple arguments to the perform method, must be JSON-serializable
* `retry` - whether to retry this job if it fails, `true` or `false`, default `true`
* `backtrace` - whether to save any error backtrace, default `false`

## Add many jobs to a queue
To add tens of thousands of jobs to a queue, it is recommended to use
```ruby
Sidekiq::Client.push_bulk('queue' => 'some_other_queue',
'class' => SomeWorker,
'args' => [[some1, arguments1],
[some2, arguments2],
[some3, arguments3],
[some4, arguments4],
])
```
It takes the same arguments as `push` above, but expects the `'args'` to be an array.
It cuts down on the redis round trip latency.
3 changes: 3 additions & 0 deletions lib/ontology_parsing_migration_worker.rb
@@ -0,0 +1,3 @@
class OntologyParsingMigrationWorker < OntologyParsingWorker
sidekiq_options queue: 'hets-migration'
end
25 changes: 25 additions & 0 deletions lib/tasks/ontology.rake
@@ -0,0 +1,25 @@
namespace :ontology do
desc 'Reanalyze old ontologies'
task :reanalyze_all => :environment do
Ontology.where(parent_id: nil, present: true).order('updated_at desc').
find_each do |ontology|
if ontology.current_version.nil?
commit_oid = ontology.repository.git.get_file!(ontology.path).oid
ontology_version_options = OntologyVersionOptions.new(ontology.path,
User.where(admin: true).first)

OntologySaver.new(ontology.repository).
save_ontology(commit_oid, ontology_version_options)
else
OntologyParsingMigrationWorker.
perform_async([[ontology.current_version.id,
{fast_parse: false, files_to_parse_afterwards: []}, 1]])
Sidekiq::Client.push('queue' => 'hets-migration',
'class' => OntologyParsingWorker,
'args' => [[[ontology.current_version.id,
{fast_parse: false,
files_to_parse_afterwards: []}, 1]]])
end
end
end
end

0 comments on commit e45a347

Please sign in to comment.