new perls v5.39.10
[andk-cpan-tools.git] / bin / analysis-jobqueue-rm.pl
blob884638235837955d229db7daf94df4597e4da532
1 #!/usr/bin/perl
3 # use 5.010;
4 use strict;
5 use warnings;
7 =head1 NAME
9 analysis-jobqueue-rm.pl -- Remove one job from the redis jobqueue on analysis
11 =head1 SYNOPSIS
13 $0 jobnumber [jobnumber...]
15 =head1 OPTIONS
17 =over 8
19 =cut
21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
23 =item B<--help|h!>
25 This help
27 =item B<--dry-run|n!>
29 Don't do anything, just tell what you would do
31 =back
33 =head1 DESCRIPTION
35 Remove a job by number. Does just this if argument is 639408:
37 2015-08-03 21:31 redis-cli get analysis:jobqueue:jobs:639408:hex
38 2015-08-03 21:31 redis-cli get analysis:jobqueue:jobs:639408:descr
39 2015-08-03 21:32 redis-cli del analysis:jobqueue:jobs:40aebf9db9a664e052e4b886d0c724bbce3cf4d4:id
40 2015-08-03 21:32 redis-cli del analysis:jobqueue:jobs:639408:hex
41 2015-08-03 21:32 redis-cli del analysis:jobqueue:jobs:639408:descr
42 2015-08-03 21:33 redis-cli srem analysis:jobqueue:runningjobs 639408
44 =cut
47 use FindBin;
48 use lib "$FindBin::Bin/../lib";
49 BEGIN {
50 push @INC, qw( );
53 use Dumpvalue;
54 use File::Basename qw(dirname);
55 use File::Path qw(mkpath);
56 use File::Spec;
57 use File::Temp;
58 use Getopt::Long;
59 use Pod::Usage;
60 use Hash::Util qw(lock_keys);
62 our %Opt;
63 lock_keys %Opt, map { /([^=|!]+)/ } @opt;
64 GetOptions(\%Opt,
65 @opt,
66 ) or pod2usage(1);
67 if ($Opt{help}) {
68 pod2usage(0);
71 use Redis;
72 use Time::HiRes qw(sleep);
73 my $redis = Redis->new(reconnect => 120, every => 1000);
74 @ARGV or pod2usage(1);
75 for my $job_id (@ARGV) {
76 if (my $hex = $redis->get("analysis:jobqueue:jobs:$job_id:hex")) {
77 my $descr = $redis->get("analysis:jobqueue:jobs:$job_id:descr");
78 warn "found job_id $job_id, hex $hex, descr $descr\n";
79 next if $Opt{"dry-run"};
80 for my $del_frag ("$hex\:id", "$job_id\:hex", "$job_id\:descr") {
81 my $del = "analysis:jobqueue:jobs:$del_frag";
82 my $ret = $redis->del($del);
83 warn "del $del => ret $ret\n";
84 die "Could not delete $del, giving up" unless $ret;
86 my $srem = "analysis:jobqueue:runningjobs";
87 my $ret = $redis->srem($srem, $job_id);
88 warn "srem $srem $job_id => ret $ret\n";
89 die "Could not srem $srem $job_id, giving up" unless $ret;
90 } else {
91 die "Failing: Job_id $job_id unknown";
95 # Local Variables:
96 # mode: cperl
97 # cperl-indent-level: 4
98 # End: