-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Add job for metadata extraction and generate BagIt packages #1366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
354f1a9
3958caf
73e67f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,126 @@ | ||||||||||||
| <?php | ||||||||||||
|
|
||||||||||||
| namespace App\Console\Commands; | ||||||||||||
|
|
||||||||||||
| use App\Jobs\ProcessMetadataExtractionBagitGenerationJob; | ||||||||||||
| use App\Models\Study; | ||||||||||||
| use Illuminate\Console\Command; | ||||||||||||
|
|
||||||||||||
| class QueueMetadataExtractionBagitGenerationJobs extends Command | ||||||||||||
| { | ||||||||||||
| /** | ||||||||||||
| * The name and signature of the console command. | ||||||||||||
| * | ||||||||||||
| * @var string | ||||||||||||
| */ | ||||||||||||
| protected $signature = 'nmrxiv:queue-metadata-extraction | ||||||||||||
| {--limit= : Limit number of studies to process} | ||||||||||||
| {--ids= : Comma-separated study IDs to process} | ||||||||||||
| {--fresh : Clear existing status and start fresh} | ||||||||||||
| {--retry-failed : Retry failed jobs}'; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * The console command description. | ||||||||||||
| * | ||||||||||||
| * @var string | ||||||||||||
| */ | ||||||||||||
| protected $description = 'Queue metadata extraction and BagIt generation jobs for eligible studies'; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Execute the console command. | ||||||||||||
| */ | ||||||||||||
| public function handle(): int | ||||||||||||
| { | ||||||||||||
| if ($this->option('fresh')) { | ||||||||||||
| if ($this->confirm('This will reset all BagIt status for all studies. Continue?', false)) { | ||||||||||||
| Study::query()->update([ | ||||||||||||
| 'metadata_bagit_generation_status' => null, | ||||||||||||
| 'metadata_bagit_generation_logs' => null, | ||||||||||||
| ]); | ||||||||||||
| $this->info('✓ Cleared all existing BagIt status data'); | ||||||||||||
| } else { | ||||||||||||
| return self::SUCCESS; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| $query = Study::query() | ||||||||||||
| ->where('has_nmrium', true) | ||||||||||||
| ->where('is_public', true) | ||||||||||||
| ->whereNotNull('download_url'); | ||||||||||||
|
|
||||||||||||
| // Filter by specific study IDs if provided | ||||||||||||
| if ($ids = $this->option('ids')) { | ||||||||||||
| $studyIds = array_map('trim', explode(',', $ids)); | ||||||||||||
| $query->whereIn('id', $studyIds); | ||||||||||||
| $this->info('Processing '.count($studyIds).' specific study IDs...'); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if ($this->option('retry-failed')) { | ||||||||||||
| // Get failed study IDs from database | ||||||||||||
| $failedStudies = Study::where('metadata_bagit_generation_status', 'failed')->get(); | ||||||||||||
|
|
||||||||||||
| if ($failedStudies->isEmpty()) { | ||||||||||||
| $this->warn('No failed jobs to retry.'); | ||||||||||||
|
|
||||||||||||
| return self::SUCCESS; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| $query->whereIn('id', $failedStudies->pluck('id')); | ||||||||||||
| $this->info('Retrying '.$failedStudies->count().' failed jobs...'); | ||||||||||||
|
|
||||||||||||
| // Reset status to pending | ||||||||||||
| Study::where('metadata_bagit_generation_status', 'failed') | ||||||||||||
| ->whereIn('id', $failedStudies->pluck('id')) | ||||||||||||
| ->update(['metadata_bagit_generation_status' => 'pending']); | ||||||||||||
|
Comment on lines
+70
to
+74
|
||||||||||||
| // Reset status to pending | |
| Study::where('metadata_bagit_generation_status', 'failed') | |
| ->whereIn('id', $failedStudies->pluck('id')) | |
| ->update(['metadata_bagit_generation_status' => 'pending']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The console command is missing comprehensive test coverage. Following the codebase convention where similar commands like VerifyFileIntegrityCommand have corresponding tests, this command should have tests covering the various options (--limit, --ids, --fresh, --retry-failed) and ensure jobs are dispatched correctly.