Skip to content

Commit

Permalink
Add --priority to bric_soap and bric_republish.
Browse files Browse the repository at this point in the history
This allows bulk publishes to be lower priority, so that active publishes by
users can take precedence.

To make it consistent, also add a `$priority` agument to the `publish` method
of Bric::Util::Burner, and have Bric::Util::Job::Pub pass in its priority.
This is so that the burner can use it when it creates the distribution job
that corresponds to the publish job.
  • Loading branch information
theory committed Jul 7, 2010
1 parent 317a77e commit aa29b6d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
12 changes: 10 additions & 2 deletions bin/bric_republish
Expand Up @@ -42,6 +42,11 @@ bric_republish [options]
--published-only - Deprecated; kept for backwards compatibility; Only
the published version of all stories will be published.
--priority - Priority for publish. Must be between 1 and 5. Defaults to
the priorities of the assets published. Useful for bulk
publishing with a lower priority, so that normal and
high-priority jobs published by users take priority.
--chunks - publish stories in chunks of this many. Defaults to 0,
which means to process them all at once. This option can
be used to avoid timing out on large jobs.
Expand Down Expand Up @@ -111,7 +116,7 @@ BEGIN {
our $no_media = 0;
our $timeout = 30;
our $chunks = 0;
our ($element, $story_id, $category, $help, $man, $site);
our ($element, $story_id, $category, $help, $man, $site, $priority);
GetOptions("help" => \$help,
"man" => \$man,
"verbose+" => \$VERBOSE,
Expand All @@ -123,6 +128,7 @@ BEGIN {
"no-media" => \$no_media,
"story-id=s" => \$story_id,
"published-only" => \my $published_only,
'priority=i' => \$priority,
"timeout=s" => \$timeout,
"chunks=s" => \$chunks,
"site=s" => \$site,
Expand Down Expand Up @@ -245,7 +251,7 @@ sub get_media_ids {

# publish stories and media found
sub publish_assets {
our ($soap, @story_ids, @media_ids, $chunks);
our ($soap, @story_ids, @media_ids, $chunks, $priority);

# do nothing if we've got nothing
return unless @story_ids;
Expand All @@ -272,6 +278,7 @@ sub publish_assets {
my $r = $soap->publish(
name( publish_ids => [ @ids[$start .. $end] ] ),
name( published_only => 1 ), # Always published_version only.
($priority ? name(priority => $priority) : ()),
);
_print_fault($r) if $r->fault;
}
Expand All @@ -285,6 +292,7 @@ sub publish_assets {
my $r = $soap->publish(
name( publish_ids => \@ids ),
name( published_only => 1 ), # Always published_version only.
($priority ? name(priority => $priority) : ()),
);
_print_fault($r) if $r->fault;
}
Expand Down
15 changes: 12 additions & 3 deletions bin/bric_soap
Expand Up @@ -97,6 +97,12 @@ Options:
--to-preview - use to_preview option for workflow publish
--priority - Priority for workflow publish. Must be between 1 and 5.
Defaults to the priorities of the assets published.
Useful for bulk publishing with a lower priority, so
that normal and high-priority jobs published by users
take priority.
--publish-date - date and time to publish assets for workflow
publish. Use format CCYY-MM-DDThh:mm:ssZ, where
the "Z" stands for UTC (GMT).
Expand Down Expand Up @@ -247,6 +253,7 @@ BEGIN {
our $without_file = 0;
our $use_related_uri = 0;
our $to_preview = 0;
our $priority;
our $publish_date;
our $published_only = 0;
our $timeout = 30;
Expand Down Expand Up @@ -274,6 +281,7 @@ BEGIN {
"use-related-uri" => \$use_related_uri,
"all" => sub { $with_related_stories = $with_related_media = 1; },
"to-preview" => \$to_preview,
"priority=i" => \$priority,
"publish-date=s" => \$publish_date,
"published-only" => \$published_only,
"desk=s" => \$desk,
Expand All @@ -298,9 +306,9 @@ BEGIN {
}
our (
$module, $command, %search, $with_related_stories, $with_related_media,
$without_file, $to_preview, $publish_date, $published_only, $username,
$password, $server, $verbose, $desk, $workflow, $timeout, $use_cookie,
$save_cookie, $chunks, $continue, $use_related_uri
$without_file, $to_preview, $priority, $publish_date, $published_only,
$username, $password, $server, $verbose, $desk, $workflow, $timeout,
$use_cookie, $save_cookie, $chunks, $continue, $use_related_uri
);

use SOAP::Lite ($verbose > 2 ? (trace => [qw(debug)]) : ()),
Expand Down Expand Up @@ -569,6 +577,7 @@ sub publish {
push @opts, name(publish_related_stories => 1) if $with_related_stories;
push @opts, name(publish_related_media => 1) if $with_related_media;
push @opts, name(to_preview => 1) if $to_preview;
push @opts, name(priority => $priority ) if $priority;
push @opts, name(publish_date => $publish_date) if $publish_date;
push @opts, name(published_only => 1) if $published_only;

Expand Down
18 changes: 18 additions & 0 deletions lib/Bric/Changes.pod
Expand Up @@ -10,6 +10,24 @@ This document lists the Changes to Bricolage introduced with each release.

=head1 Version 2.1.0 ()

=head1 Improvements

=over

=item *

Added the C<--priority> option to the C<workflow publish> command in
L<bric_soap> and L<bric_republish>. Sponsored by Denison University. [David]

=item *

Added a C<$priority> argument to the C<publish> method of
L<Bric::Util::Burner> and modifed L<Bric::Util::Job::Pub> to pass its
priority. This is so that the priority of the publish job will be replicated
as the priority of the distribution job created by the publish. [David]

=back

=head1 Version 2.0.1 ()

=head1 Improvements
Expand Down
4 changes: 2 additions & 2 deletions lib/Bric/SOAP/Workflow.pm
Expand Up @@ -290,7 +290,7 @@ sub publish {
user_id => get_user_id,
name => $name,
"$type\_id" => $obj->get_id,
priority => $obj->get_priority,
priority => $args->{priority} || $obj->get_priority,
})->save;
log_event('job_new', $job);
push @published, name( "$type\_id" => $id );
Expand Down Expand Up @@ -1213,7 +1213,7 @@ sub is_allowed_param {
publish_related_stories
publish_related_media
publish_date published_only
to_preview) },
to_preview priority) },
deploy => { map { $_ => 1 } qw(template_id deploy_ids) },
checkout => { map { $_ => 1 } qw(story_id media_id template_id checkout_ids) },
checkin => { map { $_ => 1 } qw(story_id media_id template_id checkin_ids) },
Expand Down
9 changes: 7 additions & 2 deletions lib/Bric/Util/Burner.pm
Expand Up @@ -1234,6 +1234,11 @@ The ID of the user publishing the asset.
The date to set to schedule publishing job. If not defined it will default set
up the asset to be published immediately.
=item C<$priority>
Priority to use for the distribution job. Defaults to the priority of the
business asset being published.
=back
B<Throws:> NONE.
Expand All @@ -1247,7 +1252,7 @@ B<Notes:> NONE.
sub publish {
my $self = shift;
my ($ats, $oc_sts) = ({}, {});
my ($ba, $key, $user_id, $publish_date, $die_err) = @_;
my ($ba, $key, $user_id, $publish_date, $die_err, $priority) = @_;

$publish_date ||= strfdate;
my $published = 0;
Expand Down Expand Up @@ -1321,7 +1326,7 @@ sub publish {
name => $name,
server_types => $bat,
"$key\_instance_id" => $ba->get_version_id,
priority => $ba->get_priority,
priority => $priority || $ba->get_priority,
});

# Burn, baby, burn!
Expand Down
22 changes: 17 additions & 5 deletions lib/Bric/Util/Job/Pub.pm
Expand Up @@ -116,7 +116,7 @@ Inherited from L<Bric::Util::Job|Bric::Util::Job>
=head3 $self = $job->_do_it
Carries out the actions that constitute the job. This method is called by
C<execute_me()> in Bric::Dist::Job and should therefore never be called
C<execute_me()> in L<Bric::Util::Job> and should therefore never be called
directly.
Sends the Story or Media object contained by the job to the burner. In case of
Expand Down Expand Up @@ -184,15 +184,27 @@ sub _do_it {
my $s = Bric::Biz::Asset::Business::Story->lookup({
version_id => $sid,
});
$burner->publish($s, 'story', $self->get_user_id,
$self->get_sched_time(ISO_8601_FORMAT), 1);
$burner->publish(
$s,
'story',
$self->get_user_id,
$self->get_sched_time(ISO_8601_FORMAT),
1,
$self->get_priority,
);
} elsif (my $mid = $self->get_media_instance_id) {
# Instantiate the media.
my $m = Bric::Biz::Asset::Business::Media->lookup({
version_id => $mid,
});
$burner->publish($m, 'media', $self->get_user_id,
$self->get_sched_time(ISO_8601_FORMAT), 1);
$burner->publish(
$m,
'media',
$self->get_user_id,
$self->get_sched_time(ISO_8601_FORMAT),
1,
$self->get_priority,
);
}

return $self;
Expand Down

0 comments on commit aa29b6d

Please sign in to comment.