root/branches/release-38/lib/MT/Worker/Publish.pm @ 2332

Revision 2332, 4.3 kB (checked in by bchoate, 19 months ago)

Removed MT log messages from publish worker.

  • Property svn:keywords set to Id Revision
Line 
1# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
2# This program is distributed under the terms of the
3# GNU General Public License, version 2.
4#
5# $Id$
6
7package MT::Worker::Publish;
8
9use strict;
10use base qw( TheSchwartz::Worker );
11
12use TheSchwartz::Job;
13use Time::HiRes qw(gettimeofday tv_interval);
14use MT::FileInfo;
15use MT::PublishOption;
16use MT::Util qw( log_time );
17
18sub keep_exit_status_for { 1 }
19
20sub work {
21    my $class = shift;
22    my TheSchwartz::Job $job = shift;
23
24    # Build this
25    my $mt = MT->instance;
26
27    # reset publish timer; don't republish a file if it has
28    # this or a later timestamp.
29    $mt->publisher->start_time( time );
30
31    # We got triggered to build; lets find coalescing jobs
32    # and process them in one pass.
33
34    my @jobs = ($job);
35    my $job_iter;
36    if (my $key = $job->coalesce) {
37        $job_iter = sub {
38            shift @jobs || MT::TheSchwartz->instance->find_job_with_coalescing_value($class, $key);
39        };
40    }
41    else {
42        $job_iter = sub { shift @jobs };
43    }
44
45    my $sync = MT->config('SyncTarget');
46
47    my $start = [gettimeofday];
48    my $rebuilt = 0;
49
50    while (my $job = $job_iter->()) {
51        my $fi_id = $job->uniqkey;
52        my $fi = MT::FileInfo->load($fi_id);
53
54        # FileInfo record missing? Strange, but ignore and continue.
55        unless ($fi) {
56            $job->completed();
57            next;
58        }
59
60        my $priority = $job->priority ? ", priority " . $job->priority : "";
61        $job->debug("MT::Worker::Publish publishing " . $fi->file_path . "$priority");
62
63        # Important: prevents requeuing!
64        $fi->{from_queue} = 1;
65
66        my $mtime = (stat($fi->file_path))[9];
67
68        my $throttle = MT::PublishOption::get_throttle($fi);
69
70        # think about-- throttle by archive type or by template
71        if ($throttle->{type} == MT::PublishOption::SCHEDULED() ) {
72            if (-f $fi->file_path) {
73                my $time = time;
74                if ($time - $mtime < $throttle->{interval}) {
75                    # ignore rebuilding this file now; not enough
76                    # time has elapsed for rebuilding this file...
77                    $job->grabbed_until(0);
78                    $job->driver->update($job);
79                    next;
80                }
81            }
82        }
83
84        ## MT::TheSchwartz->debug("Publishing: " . RebuildQueue::Daemon::_summary($fi));
85        MT::TheSchwartz->debug("Publishing file " . $fi->file_path . "...");
86        my $res = $mt->publisher->rebuild_from_fileinfo($fi);
87        if (defined $res) {
88            if ( $sync ) {
89                my $sync_job = TheSchwartz::Job->new();
90                $sync_job->funcname('MT::Worker::Sync');
91                $sync_job->uniqkey($fi_id);
92                $sync_job->coalesce($job->coalesce) if $job->coalesce;
93                $sync_job->priority($job->priority) if $job->priority;
94                $job->replace_with($sync_job);
95            } else {
96                $job->completed();
97            }
98            # This is way too noisy and clutters the activity log
99            # for active sites.
100            # $mt->log({
101            #     ($fi->blog_id ? ( blog_id => $fi->blog_id ) : () ),
102            #     message => $mt->translate('Background Publishing Done'),
103            #     metadata => log_time() . ' '
104            #         . $mt->translate('Published: [_1]', $fi->file_path),
105            #     category => "publish",
106            #     level => MT::Log::INFO(),
107            # });
108            $rebuilt++;
109        } else {
110            my $error = $mt->publisher->errstr;
111            my $errmsg = $mt->translate("Error rebuilding file [_1]" . $fi->file_path . ": " . $error);
112            MT::TheSchwartz->debug($errmsg);
113            $job->permanent_failure($errmsg);
114            require MT::Log;
115            $mt->log({
116                ($fi->blog_id ? ( blog_id => $fi->blog_id ) : () ),
117                message => $errmsg,
118                metadata => log_time() . ' ' . $errmsg . ":\n" . $error,
119                category => "publish",
120                level => MT::Log::ERROR(),
121            });
122        }
123    }
124
125    if ($rebuilt) {
126        MT::TheSchwartz->debug($mt->translate("-- set complete ([quant,_1,file,files] in [_2] seconds)", $rebuilt, sprintf("%0.02f", tv_interval($start))));
127    }
128
129}
130
131sub grab_for { 60 }
132sub max_retries { 0 }
133sub retry_delay { 60 }
134
1351;
Note: See TracBrowser for help on using the browser.