]> mj.ucw.cz Git - bex.git/commitdiff
New format of job IDs
authorMartin Mares <mj@ucw.cz>
Sun, 29 Mar 2015 16:00:42 +0000 (18:00 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 29 Mar 2015 16:00:42 +0000 (18:00 +0200)
Switched to "YYYYMMDD-HHMM-hash", where "hash" consists of 8 hex
digits obtained by hashing the current time, PID and a sequence number.

lib/perl/BEX/Job.pm

index 986028ed2359ffe9d8076306672b3de2951ec3da..62d076dec61205c17e4fe565b143049d95eac33c 100644 (file)
@@ -1,5 +1,5 @@
 # Batch EXecutor -- Jobs
-# (c) 2011-2013 Martin Mares <mj@ucw.cz>
+# (c) 2011-2015 Martin Mares <mj@ucw.cz>
 
 use strict;
 use warnings;
@@ -7,6 +7,7 @@ use warnings;
 package BEX::Job;
 
 use POSIX ();
+use Digest::SHA;
 
 our $job_cnt = 0;
 
@@ -24,7 +25,9 @@ sub new($;$) {
                $job->{'ID'} = $id;
        } else {
                $job_cnt++;
-               $job->{'ID'} = POSIX::strftime("%Y%m%d-%H%M%S-$$-$job_cnt", localtime);
+               my $dt = POSIX::strftime("%Y%m%d-%H%M%S", localtime);
+               my $hash = Digest::SHA::sha1_hex(join(":", $dt, $$, $job_cnt));
+               $job->{'ID'} = $dt . '-' . substr($hash, 0, 8);
        }
        $job->{'Subject'} = '';
        return $job;